Solved

Shorten variable to 100th decimal place

Posted on 2011-09-05
3
282 Views
Last Modified: 2012-05-12

I have a variable, $item_price, whose value is 55.0000

I want to shorten the number to the 100th place. I was trying to do the following but do not get output when I echo $item_price2. I wonder if I need to convert this value from a string to a number?? Thoughts?


$item_price2 = number_format($item_price, 2, '.', '');
0
Comment
Question by:pixelscape
3 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36485558
"I want to shorten the number to the 100th place...."

Do you really want 100 decimal places? Or do you mean 2 decimals? The code you have posted should work for 2 decimals. What happens when you run the script?
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 36485711
if $item_price is a string, then you have to convert it into a float first,

$item_price2 = number_format(floatval($item_price), 2, '.', '');

Open in new window

0
 

Author Comment

by:pixelscape
ID: 36485799
Thanks mankowitz. That was it.
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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

785 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