/**
* 把String转换成long
*
* @param src 要转换的String
* @param def 转换失败时返回此值
* @return 转换好的long
*/
public static long toLong(String src, long def) {
if (src == null) {
return def;
}
try {
return Long.parseLong(src);
} catch (Exception ignore) {
}
return def;
}
/**
* 把String转换成int
*
* @param src 要转换的String
* @param def 转换失败时返回此值
* @return 转换好的int
*/
public static int toInt(String src, int def) {
if (src == null) {
return def;
}
try {
return Integer.parseInt(src);
} catch (Exception ignore) {
}
return def;
} /**
* 把String转换成byte
*
* @param src 要转换的String
* @param def 转换失败时返回此值
* @return 转换好的intbyte
*/
public static byte toByte(String src, byte def) {
if (src == null) {
return def;
}
try {
return Byte.parseByte(src);
} catch (Exception ignore) {
}
return def;
}
/**
* String转换成Date
*
* @param date String
* @param pattern 样式
* @return Date
*/
public static Date toDate(String date, String pattern) {
if (date == null || pattern == null) {
return null;
}
try {
SimpleDateFormat format = new SimpleDateFormat(pattern);
return format.parse(date);
} catch (Exception ignore) {
}
return null;
}

/**
* 分转元转换,保留两位小数
* @param srcValue 源数据
* @return 结果
*/
public static double longToMoney(long srcValue) {
BigDecimal obj = new BigDecimal(srcValue);
double cny = obj.divide(new BigDecimal(100)).doubleValue();
return Double.parseDouble(String.format("%.2f", cny));
}
 
 
												

最新文章

  1. jquery选项卡
  2. 微信小程序--摸索之旅
  3. 《ASP.NET MVC4 WEB编程》学习笔记------HtmlHelper
  4. PHP操作Memcache基本函数的方法
  5. Java求和
  6. c++制作小游戏--雷电
  7. [转]hive中order by,distribute by,sort by,cluster by
  8. python django 自定义 装饰器
  9. TFS跨版本Merge测试
  10. phpMyAdmin 手动输入数据库服务器IP
  11. WPF学习(1)WPF概述
  12. Ruby 一些经常使用的细节
  13. sql必知必会-总结篇
  14. [转载]历上最强的音乐播放器(jetAudio-8.0.5.320-Plus-VX
  15. 本机不安装Oracle客户端,使用PL/SQL Developer和 Instant Client 工具包连接oracle 11g远程数据库
  16. Redis数据持久化、数据备份、数据的故障恢复
  17. js 面向对象 ES5 AND ES6
  18. AtCoder Beginner Contest 049 & ARC065 連結 / Connectivity AtCoder - 2159 (并查集)
  19. IntelliJ IDEA使用教程(简介)
  20. unable to auto-detect email address

热门文章

  1. C# .net windows服务启动多个服务 ServiceBase
  2. STL 库中的陷阱----一个难以察觉的 bug
  3. 打包ane之后在FB上生成ipa的阶段错误
  4. ListView中itemz中控件的点击事件和条目点击事件冲突
  5. listview分页加载
  6. Spring源码学习之:ClassLoader学习(1)
  7. 将本地项目上传到git总结
  8. LeetCode "Design Tic-Tac-Toe"
  9. jquery跨域请求jsonp
  10. 学习SQL的点点滴滴(一)-常用函数