EFileTahi-A Posted August 27, 2004 Posted August 27, 2004 (edited) double dPercentage; dPercentage = 700 / 500; MessageBox.Show(dPercentage) ; The messageBox outputs me "1.0" ? why? It should output "1,4"... - EFileTahi-A - Edited August 27, 2004 by EFileTahi-A Quote
Administrators PlausiblyDamp Posted August 27, 2004 Administrators Posted August 27, 2004 It's treating the 700 / 500 as an integer diviion - you need to force it to treat the numbers as doubles double dPercentage; dPercentage = 700d / 500d; MessageBox.Show(dPercentage.ToString()) ; Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Kurt Posted August 27, 2004 Posted August 27, 2004 Yes, integer division wil give you an integer that than implicitly is converted to a double (1.0). You should convert the integers first (Convert.ToDouble(700) etc...) or as mentioned add d or D as suffix to the integer number. Quote qrt
Arch4ngel Posted August 27, 2004 Posted August 27, 2004 No need to use Convert.ToDouble unless the parameter is a variable. if it's a "literal" integer you better use "d" Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.