Objective-C中double的范围是多少? [英] What is the range of a double in Objective-C?

查看:101
本文介绍了Objective-C中double的范围是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序在计算远距离.然后,我使用stringfromnumber转换距离(两倍)以插入逗号(即1,234,567).只要距离小于2,000,000,000,就可以正常工作.每当我超过20亿时,我都会得到一个负数,它也不是正确的距离.从检查帮助来看,我似乎处于两倍范围内.

I have a program where I am calculating large distances. I then convert the distance (a double) using stringfromnumber to get the commas inserted (i.e. 1,234,567). This works fine as long as the distance is below 2,000,000,000. Any time I exceed 2 billion I get a negative number that is also not the correct distance. From checking the help, I seem to be well within the range of a double.

推荐答案

一个double可以容纳从无穷大到负无穷大的任何内容.但是,它只能准确地保留15位数字.另外,请记住,如果将其强制转换为int且double存储大于2,147,483,648的值,则int会溢出为负数.

A double can hold anything from infinity to negative infinity. However It can only hold 15 digits accurately. Also, keep in mind that if you cast it to an int and the double stores something larger than 2,147,483,648, the int will overflow to a negative number.

这篇关于Objective-C中double的范围是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆