I am not able to round off up to 2 decimal digit

I have to round off a given number to exactly 2 decimal digits

i.e. 1.1111 will produce 1.11
& 1.5 will produce 1.50
& 2 will produce 2.00

and return type is double.

I don’t understand your doubt please elaborate. why do ou need double for maze path?

This question is not for maze-path

This is my personal question, and I am facing a problem with this.

I want double result with 2 digit decimal place, even a number is an integer, convert it to exactly 2 digit decimal. Like - 1 -> 1.00
2.5 -> 2.50

okay ,there are two ways to do that (inum to dnum)

  1. int to double conversion without typecasting
    double dnum = inum;

2.valueOf() method of Double class converts the passed ,value to the double value.
Double dnum = Double.valueOf(inum);

I think you are not getting my point

I know how to convert integer to double

I am facing problem while converting single decimal digit to double decimal

conversion of 1.4 to 1.40

I have tried many ways, but still facing problem in it


go through this.it has all the possible ways to change the decimal places .
if this solves your doubt please mark it as resolved :slight_smile:

The code you provided showing correct output in string, but not in double…

I think this should work too. ifyou need it as double , convert using
double d=Double.parseDouble(str);

That’s not working

I request you, plz share solution after trying that.

Converting String( 1.50 ) to double , it will give 1.5 as result

try this:

double inum=5.2;
System.out.format("%.2f", inum);

this will work

This directly prints the value

Is it possible to store it in double datatype

I couldn’t find any other way. though I think these should work in any question