Solved

PHP - stelocale & money format for Malaysia?

Posted on 2014-02-06
2
1,205 Views
Last Modified: 2014-02-07
Hi,
I am trying to work out how to alter below do display RM in front of amount instead of dollar sign?

Your help would be appreciated.


<?php

//set for money format
setlocale(LC_MONETARY, 'en_US');

echo money_format('%(#12n', '123.45');

?>
0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Assisted Solution

by:NerdsOfTech
NerdsOfTech earned 100 total points
ID: 39841281
$num = 12345678.90;
echo 'RM'. number_format($num, 2);

Open in new window

0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 400 total points
ID: 39842081
Probably unwise to rely on setLocale() since there are so many server configuration settings in play!  It would be smarter to use sprintf() or number_format() and create the exact sort of string you want to see.  My experiments:

<?php // RAY_temp_sabecs.php
error_reporting(E_ALL);

// REQUIRED FOR EURO SYMBOL
echo '<meta charset="utf-8" />';
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28358853.html
// REF http://www.php.net/manual/en/function.setlocale.php
// REF http://www.w3.org/WAI/ER/IG/ert/iso639.htm


// ACTIVATE THIS TO FIND OUT WHAT LOCALES ARE AVAILABLE ON THIS SERVER
// $x = system('locale -a');

// MALAY IS NOT ON MY SERVER
setLocale(LC_MONETARY, 'ms_MS.utf8');

// BUT SPAIN IS!
setLocale(LC_MONETARY, 'es_ES.utf8');

// SHOW DATA
print_r( localeconv() );
echo PHP_EOL;

// FORMAT SOME MONEY
echo money_format('%n', 1234.56);
echo PHP_EOL;

// SWITCH TO USA
setLocale(LC_MONETARY, 'en_US.utf8');
echo money_format('%n', 1234.56);
echo PHP_EOL;

Open in new window

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question