Moving decimal places over in a double

后端 未结 9 986
别跟我提以往
别跟我提以往 2020-11-22 16:18

So I have a double set to equal 1234, I want to move a decimal place over to make it 12.34

So to do this I multiply .1 to 1234 two times, kinda like this

<         


        
9条回答
  •  有刺的猬
    2020-11-22 16:53

    you can try integer number representation

    int i =1234;
    int q = i /100;
    int r = i % 100;
    
    System.out.printf("%d.%02d",q, r);
    

提交回复
热议问题