how to write floating value accurately to a bin file.
Posted
by user319873
on Stack Overflow
See other posts from Stack Overflow
or by user319873
Published on 2010-04-26T04:24:12Z
Indexed on
2010/04/26
4:33 UTC
Read the original article
Hit count: 211
Hi
I am trying to dump the floating point values from my program to a bin file. Since I can't use any stdlib function, I am thinking of writting it char by char to a big char array which I am dumping in my test application to a file.
It's like
float a=3132.000001;
I will be dumping this to a char array in 4 bytes.
Code example would be:-
if((a < 1.0) && (a > 1.0) || (a > -1.0 && a < 0.0))
a = a*1000000 // 6 bit fraction part.
Can you please help me writting this in a better way.
© Stack Overflow or respective owner