473,382 Members | 1,648 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,382 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 2103
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.