473,324 Members | 2,417 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,324 software developers and data experts.

Uh, what does this mean? (numeric cast conversions)

I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?

MS says:

"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."

Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards
zero"? WHAT zero?
Nov 15 '05 #1
4 2473
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?

MS says:

"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."

Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards
zero"? WHAT zero?


What do you mean, "what zero"? There's only one integral zero as far as
I know!

Take -1.1 as an example:

Round down: -2 (greatest int less than or equal to -1.1)
Round up: -1 (least int greater than or equal to -1.1)
Round to zero: -1

There's also the kind of rounding where -1.6 would go to -2, -1.1 would
go to -1, and -1.5 could go to either depending on the exact rounding
scheme - but casting doesn't do this kind of thing.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Rounded towards 0 just means that:

positive values are rounded down 3.7 --> 3
negative values are rounded up -3.7 --> -3

Bruno

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> a écrit dans le
message de news:OP**************@TK2MSFTNGP10.phx.gbl...
I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?

MS says:

"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."

Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards
zero"? WHAT zero?

Nov 15 '05 #3
On Tue, 11 Nov 2003 09:51:24 -0500, "Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote:
I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?

MS says:

"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."

Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards
zero"? WHAT zero?


"round towards zero" = truncate.

bullshark
Nov 15 '05 #4
Ah, THAT zero! Duh! Thanks. Somehow my brain got suck on the zero of 3.0
and 4.0 when reading that statement. Must need more caffeine.

"Bruno Jouhier [MVP]" <bj******@club-internet.fr> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Rounded towards 0 just means that:

positive values are rounded down 3.7 --> 3
negative values are rounded up -3.7 --> -3

Bruno

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> a écrit dans le
message de news:OP**************@TK2MSFTNGP10.phx.gbl...
I'm trying to figure out what happens when I cast a double with (int)...
does it round or drop the decimal part?

MS says:

"When you convert from a double or float value to an integral type, the
value is rounded towards zero to the nearest integral value."

Uh... what? I've hard of "rounding to the nearest integral value",
"rounding up", "rounding down", but what in tarnation is "rounded towards zero"? WHAT zero?


Nov 15 '05 #5

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

Similar topics

1
by: Bob Keith | last post by:
Hello, I am studying some source code, on which I will do some further development. I couldn't understand the following code very well. ***** stateset_result...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
11
by: Vinod Patel | last post by:
I have a piece of code : - void *data; ...... /* data initialized */ ...... struct known_struct *var = (struct known_struct*) data; /*typecasting*/ How is this different from simple...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
21
by: Karl O. Pinc | last post by:
FYI, It'd be nice if the error message from a REFERENCES constraint mentioned the column name into which the bad data was attempted to be inserted. In PostgreSQL 7.3: sandbox=> insert into...
2
by: Justin | last post by:
I have set Option Strict On I also have Enum AssemblyLineStatus As Integer My question is how come there is no compilation error when I compile following code? If...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
23
by: PeterOut | last post by:
If I had code like this. unsigned short usLimit=10 int a, i; for (i=0; i<(int)usLimit; ++i) { a=(int)usLimit; }
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.