method convertValue(value:NSString):Double;
begin
exit Convert.ToDouble(value);
end;
On the watch os simulator it works fine but on a physical device I get
MyWatchApp WatchKit Extension[538:348534] *** Terminating app due to uncaught exception ‘Exception’, reason: 'Invalid double value ‘2.454’ for locale en_CA’
if String.IsNullOrEmpty(value) then
begin
NSLog('IsNullOrEmpty');
exit 0;
end;
var aLocale := new NSLocale withLocaleIdentifier('en_CA');
var Formatter := new NSNumberFormatter;
Formatter.numberStyle := NSNumberFormatterStyle.NSNumberFormatterDecimalStyle;
Formatter.locale := aLocale;
if (value as PlatformString).rangeOfCharacterFromSet(NSCharacterSet.whitespaceAndNewlineCharacterSet).location ≠ NSNotFound then // NSNumberFormatter ignores (some) whitespace, we wanna fail
begin
NSLog('whitespace');
exit 0;
end;
//if value.StartsWith("+") and not value.Contains("-") then // NSNumberFormatter doesn't like +, strip it;
// value := valuee.Substring(1);
NSLog('numberFromString');
exit Formatter.numberFromString(value).doubleValue;
{$ENDIF}
end;
manually, do yu get the same error? i assume en_CA is Canada, does canada use “.” as decimal separator like the US do, or do you/they use “,” (like eg Germany)?
That would mean your input string has whitespace then, or else could this be hit!?
Yes its Canada, the code works fine on my mac. On the watch the method is being called from swift. I don’t think it contains whitespace because if I remove the rangeOfCharacterFromSet is returns the correct double.
The swift code is
let obj = Class1()
let roundedValue = obj.convertValue("2.454")
I did an NSLog(‘location %ld’, range.location) from the watch with and simulator and I get
9223372036854775807 and 9798692
I was wondering if the architectures might be different like one is 64bit and the other is 32 but then
I was looking at what NSNotFound was declared as and its 32bit max int.
gives you the exception " 'Invalid double value ‘2.454’ for locale en_CA’". (Can you get the full; call stack, to see whether that is from inside Formatter.numberFromString or ot (but it really has to be),
but if instead you duplicate the code from Convert.ToDouble locally, you hit the “exit ni;” clause — with the excact same input string?
What happens if you just do
var Formatter := new NSNumberFormatter;
Formatter.numberStyle := NSNumberFormatterStyle.NSNumberFormatterDecimalStyle;
Formatter.locale := "en_CA";
result := Formatter.numberFromString(aValue);
locally in your code?
hm, that’s not good, and might explain why you hit the exit clause, but it doesn’t explain why you don’t when using Convert.ToDouble from RTL2 (i’m assuming the binary we ship, not locally rebuilt?)…
in either case, that would just be hiding the exception from Formatter.numberFromString.
I think the exception is coming from RTL2 code, it matches the formatexception.
On Toffee ToDouble calls TryParseNumber and thats what I copied . I have to run on the watch because I cant repro on my mac. Its also the binary you ship.
var Formatter := new NSNumberFormatter;
Formatter.numberStyle := NSNumberFormatterStyle.NSNumberFormatterDecimalStyle;
Formatter.locale := new NSLocale withLocaleIdentifier('en_CA');
result := Formatter.numberFromString(value).doubleValue;
This does sound a bitness bug for arm64_32, yeah. can you do me a favor and run the following code for watchOS simulator, watchOS device as armv7k and watchOS arm64_32? And can you also enable the “Generate IR” option, and zip up[ and post the generated .ll for all architectures (just zip up the entire ./bin folder for the lib)?
I tried with the lines of code above and that worked but my library gives me a slightly different message
WatchKit Extension[1031:1257100] *** Terminating app due to uncaught exception ‘Exception’, reason: 'Invalid double value ‘1.28’ for locale '
It’s calling into JsonDeserializer and eventually calling Convert.ToDouble. When you said should be fixed compiler side are there other things I need ?
Oh, actually the build you grabed mighty not have bneen a full rebuiltd, and thus not have RTL2 rebuilt with the latest compiler. i’ll initiate a full rebuild.