Solved

PHP - stelocale & money format for Malaysia?

Posted on 2014-02-06
2
1,117 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
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 109

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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