Re: adding numbers in php




<rich@xxxxxxxxxxx> schreef in bericht news:djofi5018pu@xxxxxxxxxxxxxxxxxx
> In article <435f8849$0$11076$e4fe514c@xxxxxxxxxxxxxx>, Sander Peters
> says...
>>
>>Hi,
>>
>>I have the following situation:
>>
>>$a=5.6000;
>>$b=8.9000;
>>$c=($a+$b);
>>
>>echo $c;
>>
>>I will get the value '14.5' back from PHP.
>>Wich is logical.
>>But what I want is to get the value '14.5000'.
>>Is there somehow a workaround to let PHP print 4 decimals?
>>
>>Thanks in advance for your reaktion.
>>
>>Sander Peters
>>The Netherlands
>>
>>
>
> If you use "sprintf" you can format and run the calculation at the same
> time...
>
> $c = sprintf("%0.4f", $a + $b);
>
> You can then output the 4 decimal result with an "echo($c);" or "<?=$c?>"
>
> Rich
> --
> Newsguy -- http://newsguy.com
>

It works!
Thanks a lot!


.



Relevant Pages

  • Re: how to automatically logout users from my site
    ... I'm building a site using php I have a setup.php page wich has at the ... begining session_start; ... Then for each page they load do a setcookie to keep it refreshed with ...
    (comp.lang.php)
  • Re: parallel execution
    ... Thank you Mike. ... Start manually a PHP program named flip.php wich will do something, ... cron in a batch file from a host, because I can't put it on a host ...
    (comp.lang.php)
  • Re: Security isseu
    ... My website is built in HTML and PHP. ... there is a menu wich ... redirect to the main page. ...
    (alt.html)
  • how to automatically logout users from my site
    ... I'm building a site using php I have a setup.php page wich has at the ... begining session_start; ... side script too. ...
    (comp.lang.php)
  • expor java variables to php
    ... I have several java-programs, and I wich to write a class that can export ... some variables to php using the method "post". ...
    (comp.lang.java.programmer)