Skip to content

Tag: floating-point

C compatible printf output for Java

I’d want to convert float/double to string, in Java and C, such that the outputs are both consistent and user friendly. By “user friendly”, I mean the string should be human readable and sound: a maximum number of significant digits, and some automatic switching to scientific notation when a…

How to get the decimal part of a float?

I need to extract the decimal part of a float number, but I get weird results: Why does this happen? Why do I get those values instead of 0.65? Answer float only has a few digit of precision so you should expect to see a round error fairly easily. try double this has more accuracy but still has rounding error…