473,799 Members | 3,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2123
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*10 0)/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
2013
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
12209
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 "Enter 0 to exit the loop" while number != 0 :
2
6973
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 </h3> <div> box content
3
1582
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, Mozilla) sometimes the smaller columns juts out to the right of the container 1px, and sometimes doesn't reach the end by 1px. You can observe the phenomenon at http:/www.digitalovertone.com/examples/floatprob.php. All the CSS is in the header. ...
20
2700
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 this.
13
2718
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
7997
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 add the commas, I convert it to a string (specifically a char rather than an actual string object) using the gcvt function as shown below. char amt; gcvt(amount,50,amt);
14
4993
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 the sidebar is optional, i need the main content to fill the space available). ie, the green sidebar should be right up against the red header. code below
4
1892
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 tableless forms working. This again involves floats, from the bottom up through the fieldsets. For server-side programmatic reasons, the form is itself in a containing div. But the form itself isn't floated, and this is causing me problems.
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.