MoneyFormat()

Share your advanced PureBasic knowledge/code with the community.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

MoneyFormat()

Post 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. :)
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: MoneyFormat()

Post by infratec »

This is how FormatNumber() should work
And what if I don't want a currency in front?

Should I then use Trim() :?:
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: MoneyFormat()

Post by Dude »

Yep. ;) Or: ProcedureReturn Mid(m$,2)
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: MoneyFormat()

Post 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ł
User avatar
Kiffi
Addict
Addict
Posts: 1503
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: MoneyFormat()

Post by Kiffi »

take a look at the following code from srod:

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

Greetings ... Peter
Hygge
Post Reply