Solved

PHP - stelocale & money format for Malaysia?

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

728 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