Solved

PHP - stelocale & money format for Malaysia?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert html page to a php post email form automatically? 10 53
Intermittent Error on Page Loading 4 55
php simple error message 4 23
two ways encryption with php 3 25
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If 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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

786 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