Print Integer with 2 decimal places in Java

后端 未结 7 921
轻奢々
轻奢々 2020-12-16 15:10

in my code i use integers multiplied by 100 as decimals (0.1 is 10 etc). Can you help me to format output to show it as decimal?

7条回答
  •  旧巷少年郎
    2020-12-16 15:43

    you can use double instate of int. it gives you a output with decimals.

    if you want the number to stand behind the dot. you can use this:

    **int number=100;
    double result;
    result=number/(number.length-1);**
    

    I hope you can you use this.

提交回复
热议问题