gpt4 book ai didi

java - Java中printf的双%格式化问题

转载 作者:IT老高 更新时间:2023-10-28 20:24:19 24 4
gpt4 key购买 nike

%sprintf 中的一个字符串,而 %d 是我认为的小数...然而当放入

writer.printf("%d dollars is the balance of %s\r\n", bal, nm);

.. 抛出一个异常,告诉我 %d != lang.double。想法?

最佳答案

%d 用于整数,使用 %f 代替,它适用于 floatdouble 类型:

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

关于java - Java中printf的双%格式化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3853185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com