Jump to content
  • Advertisement
Sign in to follow this  
Souljah

Need help making a calculation in Java - Basic

This topic is 4626 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

Hi I have a problem in that I want a result of an IF statement I've made to perform based on the amount of credit available (to make a call) So that if the credit available is not sufficient enough to pay for the call of an entered duration (at high and low rates - depending on call duration) - if(Duration < 120 && CreditAvailable < (Duration * hRate)) { CreditUsed = Duration * hRate CreditAvailable = CreditAvailable - CreditUsed; CreditUsed = 0; - As you can see from the above this calculates the value of credit used, but I want it to change the value of duration based on the amount of credit available. I've been trying to change the type of duration to double to make it possible to make a equation to do so but keep getting the possible lack of precision error (Duration is currently INT)

Share this post


Link to post
Share on other sites
Advertisement
This might sound crasy... but its not your int thats the problem... but your double's...

Double and Float values are both floating-point values which use base two, this means they cannot store decimal fractions exactly, resulting in rounding errors and a loss of precision.

so a double value is not as presice as an integer... thats proberly why u get that message...

but as H_o_p_s posted, typecasting might solve your problem... but then u have an idea why u get that error...

You can also consider using a BigDecimal instead, since BigDecimals are exact representations of decimal fractions, and couses no precision loss...

and further u can take a look at
http://www.roguewave.com/support/docs/hppdocs/mnyapi/com.roguewave.money.currency.v1-0.BigDecimalValue.html

which i (almost) just stumbled on, which aparently provides a bit more...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!