Solved

setlocale(LC_MONETARY, 'en_US'); not working on ubuntu 12.4

Posted on 2013-12-05
6
1,028 Views
Last Modified: 2013-12-05
I have some php code displaying car prices. I'm using setlocale(LC_MONETARY, 'en_US'); to format the prices. Now this code works on my site hosted by Hostmonster, but on my ubuntu server this is not working. What could be the problem?

I forgot to add that this is not working either: money_format('%.0n' ,$row['InternetPrice']);
0
Comment
Question by:rraymond1130
  • 4
  • 2
6 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39698300
not working

Have you seen this link on the man page?
http://php.net/manual/en/function.money-format.php#86039

This also looks promising:
http://manpages.ubuntu.com/manpages/intrepid/man3/setlocale.3.html

Is there a symptom of failure that you might be able to share?  Is there a code example?  

Thanks, ~Ray
0
 

Author Comment

by:rraymond1130
ID: 39698330
Here is the code that is being used below. It works on the site hosted by hostmonster which is a Linux server. I figured it would work on a ubuntu server also since its Linux. No errors being reported:

setlocale(LC_MONETARY, 'en_US'); //Set Currency to US. This will put a $ in front of the number
$intPrice = money_format('%.0n' ,$row['InternetPrice']); //This sets the format for the dollar amount to $##,### no cents

I get a feeling their may be a package that needs to be installed on ubuntu but don't know which.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39698337
http://manpages.ubuntu.com/manpages/intrepid/man3/setlocale.3.html

I think you may need something like 'en_US.UTF-8' in setlocale()
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39698420
Testing on my server, both en_US and en_US.UTF-8 worked correctly.

<?php // RAY_temp_rraymond1130.php
error_reporting(E_ALL);
echo "<pre>";

// SEE http://www.experts-exchange.com/OS/Linux/Q_28311139.html

$x = setlocale(LC_MONETARY, 'en_US.UTF-8');
var_dump($x);

$row['InternetPrice'] = '1234.56';
$y = money_format('%.0n' ,$row['InternetPrice']);
var_dump($y);

Open in new window

0
 

Author Closing Comment

by:rraymond1130
ID: 39698422
As usual Ray, Great Help!!!! Thanks
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39698447
Thanks for the points and thanks for using EE! ~Ray
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Populate custom post type/custom fields from an external database in WordPress 3 81
NTPD Client Port Usage 12 62
Unwanted output from my query 5 40
SSH in linux 9 66
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…
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.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

740 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