|
|
| Thierry 2005-08-27, 6:55 pm |
| Hello,
I'd like to write a function who return a float with only two digits
after the point.
For instance : 12.34567 -> 12.34
Any help would be welcome
Tkx, Titi.
| |
| Janwillem Borleffs 2005-08-27, 6:55 pm |
| Thierry wrote:
> I'd like to write a function who return a float with only two digits
> after the point.
>
> For instance : 12.34567 -> 12.34
>
> Any help would be welcome
>
http://www.php.net/round
JW
| |
| Thierry 2005-08-27, 6:55 pm |
| Janwillem Borleffs a écrit :
> Thierry wrote:
>
>
>
> http://www.php.net/round
Exactly what i needed,
Thx, Titi
| |
| Hero Wanders 2005-08-27, 6:55 pm |
| Hello!
>
> http://www.php.net/round
That *rounds* the value instead of returning the float with only the
last to digits of it (ok actually Thierry asked for a function which
returns *a* float (function give($float) { return 3.14; } would do it)).
I think
function cutFloat($float)
{
return (float) floor($float*100)/100;
}
is what Thierry really searches.
Greetings,
Hero Wanders
| |
| Janwillem Borleffs 2005-08-28, 3:55 am |
| Hero Wanders wrote:
> That *rounds* the value instead of returning the float with only the
> last to digits of it (ok actually Thierry asked for a function which
> returns *a* float (function give($float) { return 3.14; } would do
> it)).
When you would have bothered to look at the manual page, you would have
noticed that the round function accepts an optional second argument to
indicate the precision.
JW
| |
| Hero Wanders 2005-08-28, 6:55 pm |
| Hello!
>
> When you would have bothered to look at the manual page, you would have
> noticed that the round function accepts an optional second argument to
> indicate the precision.
I knew this argument but the function still *rounds*.
That means:
3.145 --> 3.15
3.144 --> 3.14
My function gives:
3.145 --> 3.14
3.144 --> 3.14
Greetings,
Hero
|
|
|
|