简体   繁体   中英

Precision of the inspected floating-point values

I have this question because of the previous one . There I had a value 25.3999996185302734375 which was shown as 25.399999618530273 (without last 4 digits) in both Visual Studio 2010, Eclipse CDT, and gdb (just "print 25.3999996185302734375" in gdb and it will show 25.399999618530273).

Now, in gdb (and thus Eclipse CDT) I can issue

 printf "%.20f\n", var

to view the value with more digits.

How do I do the same in Visual Studio - ie, how do I change the precision of the inspected floating-point values?

I'm also curious if there's a way to change the default precision in both Visual Studio and Eclipse/gdb, because manually printing values is not that convenient.

As for getting more digits, you're out of luck. You're not going to get more than 17 digits out of Visual Studio (and a lot of other programming environments for that matter). With gcc, or anything based on it, you can get as many digits as you ask for.

You can check out my article Print Precision of Dyadic Fractions Varies by Language for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM