Hi,
With this code
var x := 1234.877;
Log($'{Math.Round(x,0)}');
On darwin macos I get
1235
On toffee macos I get
1235.000000
Round.zip (1.9 MB)
Cheers,
John
Hi,
With this code
var x := 1234.877;
Log($'{Math.Round(x,0)}');
On darwin macos I get
1235
On toffee macos I get
1235.000000
Round.zip (1.9 MB)
Cheers,
John
That seems to be less an issue with Round than with how the interpolated string formats the number?
Yes. Is there documentation for the string format specifier used in RTL2 ?
I don’t believe so; I should add that. That said, tis isn’t RTL2’s String.Format, this is compiler-level string interpolations and — I believe— it essentially does a ToString on each item, which mans it will use the platforms default string representation for the type, in this case Double.
For consistent formatting, I suggest to use RTL2’s String.Format
(which I believe we did add advanced summer formatting to) and/or Convert.ToString(double)
.
The Toffee version of ToString
Doesn’t appear to use locale ?
var x := 1234.877;
var currentLocale := Locale.Current;
currentLocale.NumberFormat.ThousandsSeparator := '-';
Log($'{Convert.ToString(x,0,0,currentLocale)}');
Returns 1,235
Also this doesnt appear to work
Locale.Current.NumberFormat.ThousandsSeparator := '-';
Log($'{Convert.ToString(x,0)}');
It also gives 1,235
How would I get 1235 ?
Locale.Invariant seems to do the trick but Im not sure if that intended.
I don’t think you’re supposed to modify Locales
. I’ll have to have a look at this API and see why this is even writable…
Fixed.
Hmm, indeed, it uses one for nil (current) and Invariant, but not if one is passed. Fixed.
Thanks.
If I did want to make use of NumberFormat.ThousandSeparator, doesnt SetupNumberFormatter
need to be expanded ?
For example to get * instead of , this seems to work
var x := 13234.877;
var formatter := new NSNumberFormatter;
formatter.minimumFractionDigits := 1;
formatter.maximumFractionDigits := 1;
//formatter.formatterBehavior := NSNumberFormatterBehavior.NSNumberFormatterBehaviorDefault;
//formatter.usesGroupingSeparator := true;
//formatter.groupingSeparator := '*';
formatter.formatterBehavior := NSNumberFormatterBehavior.Behavior10_0;
formatter.hasThousandSeparators := true;
formatter.thousandSeparator := '*';
var myString := formatter.stringFromNumber(x);
LOG($'{myString}');