社区
Java SE
帖子详情
如何输出小数时按规定的位数输出。。
wujevons
2001-09-11 04:19:49
如
x=12.34
OutNum(x,2) == 12.34
OutNum(x,3) == 12.340
OutNum(x,4) == 12.3400
...全文
177
3
打赏
收藏
如何输出小数时按规定的位数输出。。
如 x=12.34 OutNum(x,2) == 12.34 OutNum(x,3) == 12.340 OutNum(x,4) == 12.3400
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
wujevons
2001-09-11
打赏
举报
回复
好呀!解决了,谢谢!
vdragon
2001-09-11
打赏
举报
回复
public class numformat
{
static String num(String xx, String ii)
{
String str = new String();
try
{
float x= Float.parseFloat(xx);
int i = Integer.parseInt(ii);
if (i < 0)
{
return "i is error";
}
if (i == 0)
{
if (xx.indexOf(".") > -1)
{
str = xx.substring(0, xx.indexOf("."));
}
else
{
str = xx;
}
return str;
}
if (xx.indexOf(".") > -1)
{
int f = xx.substring(xx.indexOf(".")+1, xx.length()).length();
if (f < i)
{
for (int j = f; j < i; j++)
{
xx += "0";
}
}
else
{
xx = xx.substring(0, xx.indexOf(".") + i + 1);
}
}
else
{
xx += ".";
for (int j = 0; j < i; j++)
{
xx += "0";
}
}
str = xx;
return str;
}
catch (Exception e)
{
e.printStackTrace();
return "error";
}
}
public static void main(String[] args)
{
String x = args[0];
String i = args[1];
System.out.println("result:" + num(x, i));
}
}
rinehart
2001-09-11
打赏
举报
回复
import java.text.DecimalFormat;
String a = new DecimalFormat("###,###,###.##").format(100.5 );
System.out.println("a="+a);
结果:
a=100.50
去掉自动生成的
去掉自动生成的 在使用struts2的
时
候发现如果按照默认的方式使用标签,会自动加上标签,比如 会显示成 有
时
候并不需要这些td tr,所以可以这样写 或者在struts.xml中加入 这样全部默认使用simple 注:默认的theme是xhtml
自动换行问题
如果把标签放在中,则会自动换行。
struts 2标签
样式问题
对于struts2 ,当应用其自身的标签
时
,例如: 当查看源代码
时
为: 自动添加的table tr td 标签,但如果想 一行显示多列怎么办? 网上查了查,有好多奇怪的解决办法,比如说通过在页面上判断,看什么
时
候输入 标签,但我认为,struts2这样做,那也太不人道了,后终于查到原因,现总结如下:
struts标签之
的取值问题
struts标签之 其中:name:提交的参数名,value取值
时
须用%{}括起来。而不能写成value="#request.dict.dict_type", 否则取到的值为:#request.dict.dict_type 字符串。
struts2中的textfield设置为不可用
struts2中的textfield设置为不可用,注意使用的是 这样,即disabled="true",而不是readonly=true了, 另外,指定CSS样式,注意用的是cssClass,而不是css!
Java SE
62,622
社区成员
307,257
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章