Double % formatting question for printf in Java

前端 未结 4 1336
死守一世寂寞
死守一世寂寞 2020-12-14 15:46

%s is a string in printf, and %d is a decimal I thought...yet when putting in

writer.printf(\"%d dollars is the balance of %s\\r\\         


        
4条回答
  •  抹茶落季
    2020-12-14 16:34

    %d is for integers use %f instead, it works for both float and double types:

    double d = 1.2;
    float f = 1.2f;
    System.out.printf("%f %f",d,f); // prints 1.200000 1.200000
    

提交回复
热议问题