Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites
I bet this problem occurs because you divide DOUBLE number on INTEGER! try changing either:


double c = 10.0;


temp = a / double(c);

in your code.

Hope this helps

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!