Solved

Shorten variable to 100th decimal place

Posted on 2011-09-05
3
280 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

20 Experts available now in Live!

Get 1:1 Help Now