Number formatting

In an iOS project where I use

 cost.ToText(Locale.Current,"#,##0.#0")

where cost is a Double, I sometimes get 3 decimal places instead of 2. What am I doing wrong?

#,##0.#0

is an invalid format

try

#,##0.0#

Why not use #,##0.00

Julian, I did a test with #,##0.0# with this code:

Using Xojo.Core Dim cost As Double cost = Double.Parse(TextField1.Text.ToText) MsgBox cost.ToText( Locale.Current, "#,##0.0#")

It will put max 2 decimals, but if the second one is 0 it will not show. 1.80 will show as 1.8

This is on Mac, I can’t test for iOS right now. Will iOS be different?

I don’t know sorry, I don’t have that environment set up here to test it.

But as you mention #,##0.00 should be used for currency, even according to the docs.

It’s actually not “real” currency. Values like MCr1,234, MCr1,234.5, and MCr1,234.56 are what I’m looking for, but I sometimes get a third decimal place.

[quote=371755:@Art Gorski]In an iOS project where I use

 cost.ToText(Locale.Current,"#,##0.#0")

where cost is a Double, I sometimes get 3 decimal places instead of 2. What am I doing wrong?[/quote]

ToText formatting is based on this document:
Unicode Formatting
Picked it from developer.xojo.com

Changed:

 cost.ToText(Locale.Current,"#,##0.#0")

To:

 cost.ToText(Locale.Current,"#,##0.##")

and this seems to have fixed the problem. Thanks, everybody!

Perfect, I was thinking (because you have cost As double), that you wanted to always display 2 decimals.

Conclusion:

  • For displaying up to 2 decimals (it could be no decimals), use #,##0.##
  • For always displaying 2 decimals (usually with money), use #,##0.00