我想知道是否有人知道如何将整数限制为3位数。例如:如果输入了一个382198这样的数字,我想将其更改为382.另一个例子是如果输入了62这样的数字,我想将其更改为062.我尝试使用DecimalFormat和StringFormat,但是我两者都没有任何成功。谢谢!
答案 0 :(得分:1)
您可以这样做:
ana1$B<-factor(ana1$Burn,c("C","N","L","S"))
with(ana1,boxplot(Time~ana1$B, par(mar = c(12, 6, 4, 1)+0.1), ylab = "Infiltration Rate (m/h)" , xlab = "", las = 2, title(xlab = "Burn Treatment", line = 10), names = c( "Control" , "Not burned since 1954" , "Long rotation burn" , "Short rotation burn" ) ) )
答案 1 :(得分:0)
此示例代码显示如何使用'/'和System.out.printf
获取您想要的内容,而无需创建昂贵的对象
int val = 99;
while (val > 1000)
val = val / 10;
System.out.printf("%03d%n", val);
val = 123456;
while (val > 1000)
val = val / 10;
System.out.printf("%03d%n", val);