Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Shorten variable to 100th decimal place


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
pixelscape
Asked:
pixelscape
1 Solution
 
Beverley PortlockCommented:
"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
 
mankowitzCommented:
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
 
pixelscapeAuthor Commented:
Thanks mankowitz. That was it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now