How to get value after decimal separator for given floating point number?
Number: 129.60
Expected result: 60
                format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.
float has 7 decimal digits of precision.
The data type float has 24 bits of precision. This is equivalent to only about 7 decimal places. (The rest of the 32 bits are used for the sign and size of the number.)
Just use the Frac function.
For instance, Frac(3.14) equals 0.14. Of course, as soon as you have got rid of the integer part of the number, you can use any method of your choice to make a string out of it, like FloatToStr, FormatFloat, Format, etc.
var
  abobrinha, Expected : real;
begin
  abobrinha := 129.60;
  Expected := abobrinha - trunc(abobrinha);
end;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With