This topic is now archived and is closed to further replies.


working with decimals

Recommended Posts

leggyguy    128
Not really sure if this is a maths question or not. Anyway, I am building a small calculator, and am trying to implement some decimals. The following code is called if the decimal bool is true (which it is if the decimal key has been pressed) and a number has been entered. int c = 10; //only 1 decimal place, so we use 10, if were 2 //we would use 100, 3 use 1000, etc double temp; temp = a / c; //a is the int number entered by the user DisplayedNumberA = DisplayedNumberA + temp; //DisplayedNumberA is a double which holds our display figure Now, as far as I can see, if (double) DisplayedNumber was previously 12 and a = 5, DisplayedNumberA should now be 12.5 . But for some reason my program isn''t telling me this answer. Infact, DisplayedAnswer isn''t changing at all. I just wanted to check with you guys, that this portion of code is correct.

Share this post

Link to post
Share on other sites