字符串加倍,精度丢失

发布于 2024-12-24 20:01:21 字数 140 浏览 5 评论 0原文

当我执行 [string_variable doubleValue] 时,字符串中有 53.025709438664,我得到 53.025709。
我使用 NSLog(@"%f") 来打印它。

如何获得完整的精度值?

I have 53.025709438664 in string when I do [string_variable doubleValue], I get 53.025709.
I use NSLog(@"%f") to print it.

How I can get full precision value ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-12-31 20:01:21

请查看 中提供的格式说明符苹果文档

您无法获取小数点后的所有数字。

编辑:
如果您知道小数点后的确切位数,那么我们可以使用如下内容

NSString *s  = @" 53.025709438664";
double d = [s doubleValue];
NSLog(@"%.12f",d);

Please have a look at the format specifiers provided in Apple doc.

You cannot get all the digits after decimal point.

Edit:
If you know exact number of digits after decimal, then we could use something as follows

NSString *s  = @" 53.025709438664";
double d = [s doubleValue];
NSLog(@"%.12f",d);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文