问题标签 [nsdecimalnumber]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
numbers - NSDecimalNumber 整数整数
我试图让 NSDecimalNumber 打印出 15 位或更多位的大数字。在 15 位数时,我看到 111,111,111,111,111。超过 15 位我看到 1,111,111,111,111,110,即使被格式化的数字是 1111111111111111。
一个例子来说明我的问题:
输出如下:
我错过了什么傻事?
iphone - 在 iPhone 中做十进制数学的例子
我从 sql 表中提取十进制值作为文本字段,然后将其转换为 NSDecimalNumber(这仅仅是因为我不知道将十进制值读/写到 sqllite)。
无论如何,现在我已经碰壁了,因为我试图对这些十进制变量做简单的数学例程。例如,Sum = Balance * Interest_Rate。这个想法是我正在处理金钱计算。
你知道如何使用 NSDecimal、NSDecimalNumber 或两者来执行这些操作的示例/教程吗?
谢谢。
objective-c - how should nsdecimalnumber's be stored in the database?
What is the best way to store nsdecimalnumbers in a database? Numeric types like float, real and double are out, because it is important to preserve the precision for currency usage.
The two alternatives I have considered are string and storing two ints, one holding the mantissa and one holding the exponent. The challenge facing the latter approach is that I dont see an easy way to pull the mantissa and exponent out of the nsdecimalnumber. I can get NSDecimal from NSDecimalNumber, but the mantissa and exponent properties seem to be private! Perhaps I can reverse number = (mantissa * 10^exponent), but is there a better way to do this?
The requirement I have is that I would need to perform some aggregate sum operations on this field in the database. If I store as a string, perhaps performing this calculation would be more difficult. I would still need to write a custom function to sum over a mantissa and exponent in the database, so maybe its still as heavy.
Edit: I can access the exponent, but the mantissa is kept in a weird manner...poking at it in the debugger reveals that it is an array of short(ints).
objective-c - 从另一个方法访问时,目标 c 丢失 NSDecimalNumber 值
我将 Json 数据解析为 NSDecimalNumber,如下所示
这是一个循环,每个产品都被添加到一个数组中。最后我释放了 json 对象。
如果我在循环期间记录 product.Price 的值,则该值是正确的。然而,在应用程序生命周期的后期,我访问了数组中的一个产品并砰的一声,我得到了 EXC_BAD_ACCESS。
这是一些奇怪的指针问题,回到了随后被释放的 json 数据吗?有任何想法吗?值得注意的是,我的 NSIntegers 和 NSStrings 的值很好。
objective-c - NSDictionary 在检索时丢失小数位
我有一个类似这样的json字符串
"{"price":1.0}",使用 json 框架,我将此 json 字符串转换为 NSDictionary。
现在我从 NSDictionary 检索值如下
我只返回“1”,结果小数位和 0 消失了。
但是如果我有一个像这样的 json 字符串
"{"price":1.11}" 那么它就可以正常工作,这意味着我在文本中返回 1.11。
我在我的应用程序上显示价格信息,它看起来有点连线只显示数字 1 :)
有没有人如何取回 1.0 而不仅仅是 1?
iphone - 使用 NSLocale 的 NSDecimalNumber 欧元格式的 iPhone 货币错误?
我的应用程序使用货币值,我想以用户在 iPhone 上设置的货币和格式表示这些值,但是,在测试时,我似乎遇到了德国 EURO 格式的问题。
我有一个从货币格式化字符串返回十进制数(用于存储在核心数据中)的方法。该字符串实际上是由另一个(类似的)方法使用 NSlocale 格式化的。
我已经在英国、美国、日本和德国地区进行了测试,到目前为止只有德国造成了任何问题。
这是代码,传递的字符串例如:2,56 €</p>
}
“currencyNumber”变量打印为:-1844691245360747053200000000000000000000000000000000000000000000000000000000000000000000000000000
而在所有其他语言环境中,它将打印 2.56 以作为 NSDecimalNumber 存储到 Core Data 中。
objective-c - 过度释放 NSDecimalNumber
我的应用程序告诉我,我过度释放了下面的 NSDecimalNumber tempDouble:
我在想问题线是这个:
但我不确定为什么。我应该在分配后添加“分配、复制或保留”属性吗?当我摆脱下面的“发布”语句时,代码工作正常。
谢谢,
G
iphone - NSDecimal 与浮点数 (iOS)
我遇到过一些博客和论坛帖子,人们说在处理货币时应该使用 NSDecimalNumber 而不是浮点数。我发现我必须从 NSDecimalNumber 转换为浮点数/双精度数才能进行一些算术运算,这在我看来否定了 NSDecimalNumber 的有用性。我的意思是为什么不只使用浮点数而不为所有的转换麻烦而烦恼?
NSDecimalNumber 有什么好处,你如何对其进行算术运算?
浮点数有什么错误,而 NSDecimalNumber 没有,这就是为什么人们说在处理货币时必须使用 NSDecimalNumber?请量化误差?
在此先感谢,
希伦。
iphone - 将 NSDecimalNumber 变为负数
我正在寻找一种方法来NSDecimalNumber
通过乘以变成负数-1
。
这行得通,但感觉对于这样一个简单的逻辑来说太过分了。你能想出更好的方法来实现这一目标吗?
iphone - iPad 十进制选择器控件
我只是想知道如何为十进制数字输入制作选择器/微调器控件。我在其他 iPhone 应用程序上看到过,他们单击一个按钮,然后出现一个数字选择器,允许他们移动微调器中的数字以选择他们需要的数字。
有任何想法吗?