473,399 Members | 3,603 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,399 software developers and data experts.

rounding float toward zero?

Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.
May 9 '07 #1
5 4783
On May 9, 4:23 pm, "Yasin cepeci" <cep...@gmail.comwrote:
Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.
I think Math.Truncate(double) is what you're after.

Jon

May 9 '07 #2
Use,

Math.Floor

"Yasin cepeci" <ce****@gmail.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.

May 9 '07 #3
Yasin,

You can pass this to the static Floor method on the Math class.

Generally speaking though, you can use the following formula to find the
floor or ceiling for any number:

floor = round(number - 0.5)
ceiling = round(number + 0.5)

Assuming that rounding will round to the next highest integer for values
of .5 and above.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yasin cepeci" <ce****@gmail.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.

May 9 '07 #4
On May 9, 4:32 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Use,

Math.Floor
That would round -0.5 to -1, which isn't what the OP wants, as far as
I can tell.

Jon

May 9 '07 #5
it works thank you so much . happy days
"Jon Skeet [C# MVP]" <sk***@pobox.com>, haber iletisinde sunlari
yazdi:11**********************@p77g2000hsh.googleg roups.com...
On May 9, 4:23 pm, "Yasin cepeci" <cep...@gmail.comwrote:
>Converting single to int Rounds the upper number if the part after dot is
bigger than 0,5. But I want to discard the value after dot.

I think Math.Truncate(double) is what you're after.

Jon

May 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Steven T. Hatton | last post by:
I'm surprised I haven't hit this situation till now, but I don't believe I've had to deal with it before. I have a function that sets the components of a point class (QPoint from Qt). It takes...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
12
by: 6tc1 | last post by:
Hi all, I just discovered a rounding error that occurs in C#. I'm sure this is an old issue, but it is new to me and resulted in a fair amount of time trying to track down the issue. Basically...
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
5
by: Spoon | last post by:
Hello everyone, I don't understand how the lrint() function works. long lrint(double x); The function returns the nearest long integer to x, consistent with the current rounding mode. It...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.