c++ - Why does the same variable have different values depending on formatting -


#include <iostream> #include <stdio.h> using namespace std; int main() {     float x=1234.56;     printf("%10f\n", x);     return 0; } 

why x change value, shouldn't 1234.560000. displays 1234.560059

there's many values can represented float, , 1234.56 ain't 1 of them:

public class whatsthefloatingpoint {     public static void main(string[] args)     {         float x = 1234.56f;         bigdecimal y = new bigdecimal(x);         system.out.println(y);     } } 

this program prints closest value used: 1234.56005859375


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -