Algorithm to convert an IEEE 754 double to a string?

前端 未结 4 1915
忘了有多久
忘了有多久 2020-11-27 05:48

Many programming languages that use IEEE 754 doubles provide a library function to convert those doubles to strings. For example, C has sprintf, C++ has

4条回答
  •  情深已故
    2020-11-27 06:32

    For most example languages you quote the source is freely consultable online as they're available in open source.

    For Java, the class java.lang.Double delegates this work to sun.misc.FloatingDecimal. Check out its constructor and toJavaFormatString() method.

    For C, glibc is always a good example, and there we see that floating point output is located in its own source file.

提交回复
热议问题