I have a double value I want to convert it to an integer value. However, the double value is large enough so that it causes problems. Here is an example:
double val1 = 74.1234567890
int val2;
I want the value of val2 to be equal to 741234567890 that is without decimal point. Does anyone have any suggestions on how to accomplish this?
And what do you want from
74.1234560000. If it’s always 10 digits,val * 1e10, then conversion to a suitably large integral type, does the job. Otherwise, you’ll have to define more clearly what you want. If it is based on the string used to initialize thedouble, there it can’t be done; many different strings can result in exactly the same internal value, including strings that would represent different values if interpreted as a real. At the other extreme, if you want the smallest integer value such that the value, multiplied by some negative power of 10, is exactly the value of the float… most floating point values will require something like 52 decimal digits, and the results almost certainly won’t fit on any native integral type.