A problem of setting precison
I appreciate all the answers from you, thank you very much.
I must stress, the program I wrote is a Win32 program, so I can not use C++, I just want to know if I can find a way to control the float value's precision using C instead of C++:
I recently wrote a programme under Win32 environment, I have a problem which I can not solve independently.
double a ;
TCHAR *k = "152.3", DigitArray[ 100 ] ;
a = strtod( k, NULL ) ; // convert a string to double.
a + = 100 ;
_gvct( a, 100, DigitArray ) ; //Convert double to string.
TextOut( hdc, 0, 0, DigitArray, NULL ) ;
The value of 'a' would be shown as 252.29999999999993, just becaue the default precision is 14 after the decimial point, I hope the value is 252.3 instead of 252.29999999999993, so I wish somebody can tell me a way to solve the above-mentioned problem.
IMPORTANT:
Only C language is acceptable, any methods based on C++ is
not valid !
Thank you very much!
Your way is not efficient!
because it includes the operation of FILE read-out and write-in, I think it is not necessary at all.
Re: Your way is not efficient!
Quote:
Originally posted by ysapex
because it includes the operation of FILE read-out and write-in, I think it is not necessary at all.
where do you think is file i/o used?
s[printf|scanf] are buffer related, i. e. memory related.
Go read some books on the basics of C.