标签:double
JAVA实现保留两位小数
double fk = fkyfk==0?0:(fkyfk - fkwfk) / fkyfk;
double jj = jjyfk==0?0:(jjyfk - jjwfk) / jjyfk;
BigDecimal bfk = new BigDecimal(fk);
BigDecimal bjj = new BigDecimal(jj);
int fk1 = bfk.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
int jj1 = bjj.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
//
double fk1 = bfk.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
double jj1 = bjj.setScale(2, BigDecimal.ROUND_HALF_UP). doubleValue ();
数据库中用SQL实现:
decode (
TOTAL,--分母
0,
‘0%‘,
(dec (cast (FACT AS FLOAT) / TOTAL + 0.005,
10,
2)
* 100
|| ‘%‘))
AS FKLV
标签:double
原文地址:http://tianjian.blog.51cto.com/3549910/1665924