UmBottesWillen
UmBottesWillen

Reputation: 107

How to turn an integer value into a double decimal value?

I want to parse two integer values into a double value, where the end product should look like this:

int value;
int decimalValue;
double result;

result = value . decimalValue;

How can I do this most elegantly for integer values of variable lengths?

Edit: What I could do is something like this:

String temp = String.valueof(decimalValue);
int i = temp.length();
double d = decimalValue;

for (i > 0; i--) {
    d / 10;
}

d = d + value;

However, I wouldn't call that very elegant. Is there a better solution for my problem?

Edit: Was made aware of a flaw in my thinking. As such, I am using now Strings instead of integer values and BigDecimal instead of a double value.

Upvotes: 2

Views: 652

Answers (1)

Dr. Confused
Dr. Confused

Reputation: 76

Double.parseDouble(value + "." + decimalValue);

But like Hovercraft Full Of Eels said in the comments storing something like 003 in an integer will not work.

Upvotes: 1

Related Questions