217 posts
  • Has been part of the Envato Community for over 6 years
  • Has sold $5,000+ on Envato Market
  • Located in Canada
  • Has collected 1+ items on Envato Market
+1 more
CreativeStable says

I am not sure if anyone can help me but I would really appreciate it.

I have a page that pulls information from the Globe Investor’s api. It is xml so I pull it in, parse it, and spit it back out with php.

A snippet of my code looks something like this (not including the xml parser).

<?php $last = $result['s:service']['s:content']['stock'][1]['quote']['last']; $lastint = round($last, 3)+0; ?> <div class="LastPrice">Last Price <?php echo($lastint); ?></div>

The round part ads a zero before the decimal point so that it spits out: Last Price 0.29

rather than just .29

HOWEVER , here is my problem. I need there to be one more integer to the right of the decimal, even if it is zero.

Any ideas?

385 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+8 more
uDesignStudios says

Hi,

there is a handy function to do just that! Its called number_format();

echo number_format($lastint, 3);

the 2nd parameter defines how many digits you want after the decimal point. There are two other optional arguments to define thousands and decimal separator character, so you could format the number like we do in my country 1 000,00 or like its done in the US 1 ,000.00

here is php manual page if you need further details: http://cz2.php.net/manual/en/function.number-format.php

Hope it heps, uDesignStudios

217 posts
  • Has been part of the Envato Community for over 6 years
  • Has sold $5,000+ on Envato Market
  • Located in Canada
  • Has collected 1+ items on Envato Market
+1 more
CreativeStable says

ohhhhh my gosh you are my favorite person in the entire world right now :P Thank you that was very helpful and everything is working how I want now :)

385 posts
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+8 more
uDesignStudios says

I’m glad I could help ;)

by
by
by
by
by
by