#### Archived

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

# working with decimals

This topic is 5977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
I bet this problem occurs because you divide DOUBLE number on INTEGER! try changing either:

  double c = 10.0;

or

  temp = a / double(c);

Hope this helps

##### Share on other sites
you''re right, I really should have checked that, I thought it would be something that wasn''t my fault.

Silly me.

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999758
×