I want to ask about NSDecimalNumber. is it any changes for use this function ? i test use number like this.
example: a = "1000000.0" var a i make number formatter use NumberFormatter
b = NSDecimalNumber(string: a with number formatter).decimalValue
i try to print b. the value return 1. Anyone can help ?
i will send the email
I can’t provide one-on-one technical support via email, but I’m happy to continue this discussion here.
To set the stage, Foundation is receiving major surgery in this year’s OS releases as part of the effort discussed in What’s next for Foundation. This work will produce compatibility problems, and it’s important to test your code on the latest betas and report any problems you see.
However, NSDecimalNumber
is a tricky type so, before sending you down that path, I first wanna have a quick look at your test case. Thanks for posting that.
Your code is kinda strange, but I presume that that’s the result of your distilling this down into a test case. Running it on iOS 18.0b2 I see that formattedAmountIgnoreFraction
is returning a string with group separators (commas in my case) and that’s causing NSDecimalNumber.init(string:)
to return the wrong value. That seems to be a bug in NSDecimalNumber.init(string:)
. The documented makes it clear that it should be handling group separators.
So, you should definitely file a bug about that. Please post your bug number, just for the record.
As a temporary workaround, you could change formattedAmountIgnoreFraction
to return a string without group separators (set usesGroupingSeparator
to false), and then you’ll get the correct result.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"