Fill double zero left in java

Asked

Viewed 970 times

0

I would like to know how to format a doouble with two boxes to the left of the dot and two to the right of the dot.

Example: I have double 1.1

I want it formatted to 01.10;

input: 10.1 / 1.05

output : 10.01 / 01.05

  • Possible duplicate of http://answall.com/questions/30701/formata%C3%A7%C3%A3o-de-um-double-in-java? Rq=1

  • Actually I wanted the double to be formatted and not a string. When I use the example mentioned in the linked topic it is formatting to 10.0, when I wanted it to format to 10.00. Decimalformat = new Decimalformat("#.##"); number = Double.valueOf(format.format(number)); System.out.println(number); output: 10.0

  • I need to sort the values of double 01.20 is higher than 01.11 but is considering 01.2 ,so the ordering is wrong.

  • What you said doesn’t make sense. 1.2 > 1.11 In math, it’s not because you’re missing a zero that 1.11 is bigger. Double is a number, zeros on the left make no difference in any operation, just as zeros on the right after comma also do not.

  • I don’t think you understand. The system carries a list of decimal numbers. [1.5; 1.10; 1.15; 2.5] when I sort these numbers sort as follows: [1.1; 1.15;1.5;2.5] that is, the zero of 1.10 has been de-activated.

  • Yes, because zero right after comma does not interfere with anything. Ordering is perfect. I don’t understand what result you want.

  • The problem is that [1.10 ; 1.9 ; 1.0] is getting [1.0 ; 1.1 ; 1.9], my question is how do I consider 1.10 and not 1.1

  • Make it whole in ordination then. I say, 110 > 19 > 10, I imagine that’s what you want.

  • Thanks man! I turned it into a whole and it worked.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.