Page 1 of 1

MoneyFormat()

Posted: Thu Jun 09, 2016 1:45 pm
by Dude
I prefer this over FormatNumber(), as it uses local PC settings for the currency symbol, decimal separator, and thousands separator:

Code: Select all

Procedure.s MoneyFormat(amount.d)
  m$=Space(999)
  GetCurrencyFormat_(0,0,StrD(amount,2),0,@m$,990)
  ProcedureReturn m$
EndProcedure

Debug MoneyFormat(91397.45000) ; $91,397.45
This is how FormatNumber() should work, IMO. :)

Re: MoneyFormat()

Posted: Fri Jun 10, 2016 6:49 am
by infratec
This is how FormatNumber() should work
And what if I don't want a currency in front?

Should I then use Trim() :?:

Re: MoneyFormat()

Posted: Fri Jun 10, 2016 1:15 pm
by Dude
Yep. ;) Or: ProcedureReturn Mid(m$,2)

Re: MoneyFormat()

Posted: Fri Jun 10, 2016 3:24 pm
by cas
Beware, some locales have currency symbol in front of numbers and some at end. Do not use Trim() od Mid() if your app will be available to users from different countries. Here are some examples:
Germany:

Code: Select all

91.397,45 €
France:

Code: Select all

91 397,45 €
Iceland:

Code: Select all

91.397 ISK
Italy:

Code: Select all

€ 91.397,45
Poland:

Code: Select all

91 397,45 zł

Re: MoneyFormat()

Posted: Fri Jun 10, 2016 8:53 pm
by Kiffi
take a look at the following code from srod:

http://www.purebasic.fr/english/viewtop ... 85#p241585

Greetings ... Peter