0
How to add part of number( which is type double) to int
I was working with phone numbers and because int can store 10 digits, i stored it in double, but later i need to take with % part of that number and store it in integer, just it is showing double value with +10e( idk if i wrote correct but you get format of data type double). Can someone help me how to get double number in "normal" format.( i don't work with floating point, number is without decimal places)
3 Answers
+ 4
Save the number in a string and only convert it (or parts of it) to an integer or other number format when you actually want to use it as a number. Splitting a string into several parts is much easier than doing the same with a numerical value
+ 2
`int` can't store long numbers...
But, `long long int` can do the job. For example,
long long int number = 1234567890; // ten-digit number
std::cout << number; // prints the number
Note: It works only in C++11 and higher.
0
Thanks but i need to save value bigger than 10 digits( without creating array) then i do that value %pow(10,x) to take part of that " double" value and store it in int, but it immediately stores it with exponential so i can't take part of it and store it in integer
for example:
double a = 38763487713;// it stores it as 0.0000387*e10( it isn't correct but i hope you get what is my problem
int b = a/pow(10,6);
a/=pow(10,6);
int c = a/pow(10,3);
a/=pow(10,3)
so i divide it on parts which are for country code, national destinatio code, subsriber network code...
i found some solutions but it is just for output:
cout<<std::fixed();
but i need to use it for calculations