473,247 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,247 software developers and data experts.

float reduced

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
5 2101
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: j vickroy | last post by:
Howdy, I do not understand the following behavior for: PythonWin 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32. >>> >>> float('0.0') 0.0 >>> row = ('0.0', '1.0', None)
6
by: Artemisio | last post by:
I am a non programmer who just started with Python. So far I love it. I would appreciate if you could help me fix this error I get taking this exercise: count= 0 sum= 0.0 number= 1 print...
2
by: Marek Mänd | last post by:
I have simple structure like: <div> <h3 style="text-align:center;"> <span style="float:right;">input type="image"/></span> <span style="float:left;">input type="image"/></span> boxes titlebar...
3
by: Kyle Matthews | last post by:
Hello all, I am currently working on a 2 column layout in which the smaller column is fixed at 100px, and the larger column takes up the remaining space. In Gecko browsers (Firefox, Netscape,...
20
by: Joe exCSSive | last post by:
Hi, folks: I'm back...and now I'm really stuck !! I have a graphic ( http://www.sundialontario.com/images/makeitatable.jpg ) that I would like to convert to CSS and I'm not sure how to do...
13
by: Link | last post by:
I have to convert an float number to int without using casting i= (int) f, without printf and others. I can only use int, char and structs. Can anyone help? Thanks Juerg
5
by: Bryan R. Meyer | last post by:
I am a relatively new C++ programmer and am attempting to write a function that takes a number of type float and adds commas to it in the appropriate places. In order to manipulate the number to...
14
by: Mark | last post by:
please view http://mnbayazit.com/misc/sample.gif i'm wondering how i can make the sidebar (green) float to the right of the main text, without specifying the width of the main content (because...
4
by: Jay Levitt | last post by:
I'm working on a site with a three-column-float, liquid-center layout that I believe came from ALA. So, from the top down, the columns are floats. In the center column, I'm working on getting...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.