Formating Number

Hi,
I want to format number,

[code] dim sx,sx1,sx2 as Double
dim a,b,c as string
sx=1500000
sx1=-200000
sx2=20000
a=format(sx, “###,##0”)
b=format(sx1, “-###,##0”)
c=format(sx2, “###,##0”)

MsgBox str(a)+EndOfLine+str(b)+EndOfLine+str©[/code]

this code showing the result as expected.

1,500,000 -200,000 20,000

How to get the result like,

1.500.000 -200.000 20.000

without changing the database data type and current region.

any help ?

thanks
Arief

Have a look at http://developer.xojo.com/double$ToText

a = replaceall( a, ",",".")

For me the above code without change anything give the second results …

1.500.000 -200.000 20.000

Maybe have to do with locale?

Yes. Format uses the user’s locale info. Str uses the characters in the formatting string.

I have tried this,

[quote]Dim locale As New Xojo.Core.Locale(“en-US”)
Dim n As Double = 12394567
Dim t As Text = n.ToText(Locale.Current, “#.###.###”)

MsgBox str(t)[/quote]

but giving an error, no result.

thanks
Arief

for some reason, i cant use this method, because I’m putting other code using regex to remove duplicate row.

Thanks
Arief

[quote=393440:@Arief Sarjono]I have tried this,

but giving an error, no result.

thanks
Arief[/quote]
Don’t mix ToText and Str. Use one or the other.

Try

Dim n As Double = 12394567 Msgbox Str(n, "#.###.###")

This is the problem, I cant change the locale setting in windows control panel, because there is already an app in my pc that not allowing me to change it, otherwise it wont work.

thanks
arief

[quote]Dim n As Double = 12394567
Msgbox Str(n, “#.###.###”)[/quote]

the result that I got here is 12394567.

This code working fine for me

[code]Dim locale As New Xojo.Core.Locale(“en-US”)
Dim n As Double = 12394567
Dim t As Text = n.ToText(Locale.Current, “#.###.###”)

MsgBox str(t)[/code]

Results = 12.394.567
I forget to put this…

[code]
Dim locale As New Xojo.Core.Locale(“el-GR”)
Dim decimal As Text
decimal = locale.DecimalSeparator
Msgbox decimal
Results (,)

Dim locale As New Xojo.Core.Locale(“en-US”)
Dim decimal As Text
decimal = locale.DecimalSeparator
Msgbox decimal
Results (.)[/code]

still no work here…:frowning:

thanks
arief

[quote=393446:@Loannis Kolliageorgas]This code working fine for me

[code]Dim locale As New Xojo.Core.Locale(“en-US”)
Dim n As Double = 12394567
Dim t As Text = n.ToText(Locale.Current, “#.###.###”)

MsgBox str(t)[/code]

Results = 12.394.567
I forget to put this…

Dim locale As New Xojo.Core.Locale("el-GR")
Dim decimal As Text
decimal = locale.DecimalSeparator
Msgbox decimal
Results ([b],[/b])

Dim locale As New Xojo.Core.Locale("en-US")
Dim decimal As Text
decimal = locale.DecimalSeparator
Msgbox decimal
Results ([b].[/b])[/code][/quote]

The mac api being used by the framwork is different to the windows api, the mac api allows the use of . as a group separator but it doesnt work on windows which is where the error came from above that Arief reported in an earlier post.

The above code is only working because your locale has a . for its group separator as the code isn't actually using the one defined in that code snippet.

You'll need the following to work across all platforms:

[code]Dim l As New Xojo.Core.Locale("es")
Dim n As Double = 12394567
Dim t As Text = n.ToText(l, "#,###") // add .### onto the end if you want to deal with decimals which will be separated with ,

MsgBox(t)

As Spain uses a . for its group separator it should work for you, tested ok on windows and mac.

thanks,

its worked now…

regards,
arief

Glad you got it working :slight_smile:

Technically you don’t even need to specify the formatting in the above example as Spain uses the format you want, you could just use this in the above code instead:

Dim t As Text = n.ToText(l)