#How to convert a long to a double using casting?

5 messages · Page 1 of 1 (latest)

polar dawn
#

My program is a calculator which uses "long" to account for larger numbers. But when it comes to division, I need to convert it to a double so that it has the decimal. I've tried to use "doubleValue()"/"(double) variable[Casting]" but each time I wasn't able to get it to work (If it was 1/3 for example it would return 0). Any ideas? (variables number_one/two, etc, are user inputted). Site is at "case /" where I tried some things for a while

shadow kindleBOT
#

This post has been reserved for your question.

Hey @polar dawn! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

gusty gulch
#

You are most likely performing the cast after doing the division. Try:

double d = (double)number_one / (double)number_two;```
polar dawn
#

Oh, it works now. Hadn't even thought of that. Thanks!