Solved

PHP - stelocale & money format for Malaysia?

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now