You are here:

PHP5/Number format issue in cron

Advertisement


Question
Its a strange issue for me,

When I run a PHP script through CLI, eg : 'php filename.php'

and filename.php contains <?php $number=1.25; echo $number; ?>

it gives me output as "1,25"(see the comma) expected result was "1.25" .

and when I Run the script like "wget http://domain.com/filename.php"
it gives correct out put ie 1.25

Our server hosted in spain and number format in spain is different.

But I dont know how and where to change config settings.
Can you Please explain.?

Thanks,
bejoy

Answer
Hello bejoy,
         It seems that your locale has been set to dutch. So, you are getting comma(s), instead of dot(s).

So, you must first set your locale to "US" format. To do so, just use the following format.

setlocale(LC_ALL,"US");

So, your entire program should look like,

<?php
setlocale(LC_ALL,"US");
$number=1.25;
echo $number;
?>

In future, please do think twice, if you are setting your locale to "Dutch", as it might result in unwanted conversions.

Hope this resolves your issue.

Don't hesitate to write back to me for clarifications.

All the very best and good luck.

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


Vimal Abraham

Expertise

I can be able to solve PHP, MySQL and Web Hosting (Linux) related issues that may include cPanel/WHM.

Experience

I have worked under various domains of web development including file sharing, social community, wallpaper management, image hosting, web hosting automation, shopping cart and payment gateway integration. My active portfolios include, http://www.4kwallpapers.in http://www.wallpicz.com

Education/Credentials
I have completed Bachelor of Engineering in Computer Science.

Awards and Honors
Have a Total of nine certificates in Inter and Intra College Competitions that includes technical quiz, program debugging and paper presentation (State Level).

©2016 About.com. All rights reserved.