By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,949 Members | 2,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,949 IT Pros & Developers. It's quick & easy.

float reduced

P: n/a
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.
Aug 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Aug 27 '05 #2

P: n/a
Janwillem Borleffs a écrit :
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


Exactly what i needed,
Thx, Titi
Aug 27 '05 #3

P: n/a
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


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
Aug 27 '05 #4

P: n/a
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

Aug 28 '05 #5

P: n/a
Hello!
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.


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
Aug 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.