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!

31st May 2019, 8:50 AM
Noverdi Ramadhan
Noverdi Ramadhan - avatar
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.
31st May 2019, 9:25 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
https://code.sololearn.com/cALNofdGw74Z/#cpp Catch the case that the number does not have decimal part
31st May 2019, 10:04 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Thanks for all the answer!
1st Jun 2019, 2:40 AM
Noverdi Ramadhan
Noverdi Ramadhan - avatar