Re: adding numbers in php
- From: "Sander Peters" <sanderpeters@xxxxxxxxx>
- Date: Thu, 27 Oct 2005 10:20:05 +0200
<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!
.
- Prev by Date: Re: Serving PDF document outside www root problem.
- Next by Date: Re: Best Beginner PHP Editor?
- Previous by thread: Abstract Factory and Factory Method OO Design Patterns using PHP5
- Next by thread: $_REQUEST empty despite $HTTP_RAW_POST_DATA being full?!?
- Index(es):
Relevant Pages
|