NumberUtil
2015-10-14 11:01
387 查看
/** * @author dawson dong */ package com.kisstools.utils; import java.math.BigDecimal; import android.text.TextUtils; public class NumberUtil { public static double multiply(double d1, double d2) { BigDecimal bd1 = new BigDecimal(Double.toString(d1)); BigDecimal bd2 = new BigDecimal(Double.toString(d2)); double result = bd1.multiply(bd2).doubleValue(); return result; } public static int parse(String text, int dv) { if (TextUtils.isEmpty(text)) { return dv; } text = text.trim(); int value = dv; try { value = Integer.parseInt(text); } catch (Exception ignore) { } return value; } public static double parse(String text, double dv) { if (TextUtils.isEmpty(text)) { return dv; } text = text.trim(); double value = dv; try { value = Double.parseDouble(text); } catch (Exception ignore) { } return value; } public static float parse(String text, float dv) { if (TextUtils.isEmpty(text)) { return dv; } text = text.trim(); float value = dv; try { value = Float.parseFloat(text); } catch (Exception ignore) { } return value; } }
相关文章推荐
- Linux sort 命令的用法
- UITableViewCell 高度计算从混沌初始到天地交泰
- 收藏一个IOS好东西的链接
- 一个程序猿坎坷之路,随笔
- leetcode 198 House Robber(难易度:Easy)
- pfx文件解析私钥和公钥
- LT8522X取代MS9282 VGA转HDMI HDMI转VGA VGA和HDMI矩阵
- PHP图像处理之---图片的缩放
- shell基础:使用read、命令行脚本传参实现输入2个整数并计算
- redis机制总结
- mybatis(3)SqlMapConfig.xml配置
- Codeforces #322 div2 ABCDF
- Mathematica求导数
- POJ2456 Aggressive cows 最大值最小化(二分)
- Spring @Resource、@Autowired、@Qualifier的注解注入及区别
- 流的读取
- KJMusic完整音乐项目
- POJ 1273 Drainage Ditches 最大流
- iOS原生开发获取当前设备日期与时间
- java 解压缩代码