Problem with Format

Here is a number (n) I am trying to print: 33883.67
s(string) = Format(n, formatSpec)

If I use this formatSpec: “###,###,###.00;-###,###,###.00;”
I get this: 33,883.67

If I use this formatSpec: “\€###,###,###.00;-\€###,###,###.00;”
I get this: €33,883.7
What I would like is: €33,883.67

I’m clearly missing something obvious!

This?

Dim s as String s=Format(33883.67, "\\€###,##0.00") TextField1.text =s
And this maybe help you.

Dim s as String dim n as Double = 33883.67 s=Format(n, "\\€###.###,##") TextField1.text =s //=€33.883,67

n is already a double.
I am printing the string (using “g.DrawString(s,x,y)”, not putting it in a TextField.
Your second example uses the continental system - comma for the decimal, full stop for thousands - which I don’t want.

Thanks for your suggestion.

Seems to me, with FORMAT you MUST use “comma” for thousands, and “period” for decimal, and FORMAT will alter it internally based on the users locale settings.

And Drawstring or putting in a textfield, the manner in which you use FORMAT is still the same

I can recreate the loss of the second decimal of precision.
.67 without the currency symbol, and .7 if it is included.

Dont know why that would happen (sounds like a bug) , but this probably gets what you want:

s = replace("€" + format(n, "###,###,###.00;-###,###,###.00;"),"€-","-€")

the tricky part getting the - sign before the € sign…

Im sure there will be better ways suggested, but if you are in a hurry…

This seems to work fine: if n < 0 then s = “-€” + s else s = “€” + s

Seems like a bug in Format to me.

Thank you again.

Try double.ToText
http://developer.xojo.com/double$ToText

Thanks Norman, but I couldn’t get that to work with the currency symbol.

ToText will, or can be, set up to make strings look “proper” for the users current locale settings.
So you’d get the euro symbol in countries where they use that, commands for decimal separators where they use that etc.
It’s intended to be for display purposes.

Now when you know you want to display a number in a specific format (say whats correct for France) then you can specify a specific locale and the formatting rules for that locale will be applied.

The ONLY place where this doesn’t work quite the way you might hope is on the web because the app runs ON THE SERVER not on the persons computer - so you get the formatting that is appropriate for the SERVER and its locale.
That is one place where you pretty much vae to track the users locale in the session and then use a specific locale.

So something like

 dim n as double = 33883.67
  
   // format things for whatever the CURRENT locale is
  dim t as text = n.ToText( xojo.core.Locale.current, "¤###,###,###.00;-¤###,###,###.00")
  
  msgbox t

   // format things for french in France
  t = n.ToText( New Xojo.Core.Locale("fr-FR"), "¤###,###,###.00;-¤###,###,###.00")
  
  msgbox t