0
Is there a function that return a decimal point value from a double/float ?
Maybe there's a function that I don't know, that works a little bit like this: double x = 699.25; int n = getPoint(x); std::cout << n; //outputs 25 You get the point (:p). Is there a function, or a way I can do that? Thanks in advance!
4 Answers
+ 4
No function that I know of, but if you want to extract floating point you can do something like this:
double x = 699.25
double y = x - (int)x; // 699.25 - 699
Then you are left with 0.25 or any floating point number you want. If you wanna get rid of "0." you can multiply number by 100, or use "to_string" method and then delete first 2 characters from front.
+ 1
https://code.sololearn.com/cALNofdGw74Z/#cpp
Catch the case that the number does not have decimal part
0
Thanks for all the answer!