Click here to Skip to main content
15,913,941 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 5:23
CCG311-Nov-08 5:23 
GeneralRe: How to round a double correctly... Pin
Guffa11-Nov-08 7:09
Guffa11-Nov-08 7:09 
GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 7:39
CCG311-Nov-08 7:39 
AnswerRe: How to round a double correctly... Pin
sph3rex11-Nov-08 5:16
sph3rex11-Nov-08 5:16 
GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 5:21
CCG311-Nov-08 5:21 
GeneralRe: How to round a double correctly... Pin
Fabio V Silva11-Nov-08 5:25
Fabio V Silva11-Nov-08 5:25 
GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 5:31
CCG311-Nov-08 5:31 
GeneralRe: How to round a double correctly... Pin
Dave Kreskowiak11-Nov-08 7:07
mveDave Kreskowiak11-Nov-08 7:07 
You might want to double check the results and do some testing to see if it's going to work for you. Also, doing math on the number you want to round while using a Double type can affect how rounding works.

For example, Doing something like: Math.Round(1.255, 2) results in 1.25, not 1.26. What happens is that 1.255 is multiplied by 100 (the 2 parameter), then the number is rounded to the nearest integer. But, with the Double type, this results in 1.255 * 100 = 125.4999999999, which will round DOWN to the nearest integer of 125. This is then divided by 100, which results in 1.25. If accuracy is mandatory, consider using the Decimal type. It's slower since it's not a native CPU data type, but it is more accurate.


A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008




GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 7:25
CCG311-Nov-08 7:25 
GeneralRe: How to round a double correctly... Pin
Dave Kreskowiak11-Nov-08 8:02
mveDave Kreskowiak11-Nov-08 8:02 
GeneralRe: How to round a double correctly... Pin
CCG311-Nov-08 8:20
CCG311-Nov-08 8:20 
GeneralRe: How to round a double correctly... Pin
Dave Kreskowiak11-Nov-08 9:48
mveDave Kreskowiak11-Nov-08 9:48 
General[Message Deleted] Pin
CCG311-Nov-08 7:32
CCG311-Nov-08 7:32 
GeneralRe: How to round a double correctly... Pin
Jon_Boy11-Nov-08 8:15
Jon_Boy11-Nov-08 8:15 
AnswerRe: How to round a double correctly... Pin
ian dennis17-Nov-08 11:14
ian dennis17-Nov-08 11:14 
QuestionBorderless Form Pin
Gagan.2010-Nov-08 23:13
Gagan.2010-Nov-08 23:13 
AnswerRe: Borderless Form Pin
Thomas Stockwell11-Nov-08 2:47
professionalThomas Stockwell11-Nov-08 2:47 
GeneralRe: Borderless Form Pin
Gagan.2011-Nov-08 4:08
Gagan.2011-Nov-08 4:08 
GeneralRe: Borderless Form Pin
Thomas Stockwell11-Nov-08 4:31
professionalThomas Stockwell11-Nov-08 4:31 
QuestionNeed Help In Vb.net Pin
sarfarazaliqureshi10-Nov-08 22:18
sarfarazaliqureshi10-Nov-08 22:18 
AnswerRe: Need Help In Vb.net Pin
Gagan.2010-Nov-08 23:04
Gagan.2010-Nov-08 23:04 
GeneralRe: Need Help In Vb.net Pin
sarfarazaliqureshi11-Nov-08 8:04
sarfarazaliqureshi11-Nov-08 8:04 
AnswerRe: Need Help In Vb.net Pin
Thomas Stockwell11-Nov-08 2:49
professionalThomas Stockwell11-Nov-08 2:49 
GeneralRe: Need Help In Vb.net Pin
sarfarazaliqureshi11-Nov-08 8:09
sarfarazaliqureshi11-Nov-08 8:09 
GeneralRe: Need Help In Vb.net Pin
Thomas Stockwell11-Nov-08 8:17
professionalThomas Stockwell11-Nov-08 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.