单位转换类UnitUtil2
package com.jlb.scan.util; import java.math.BigDecimal;
import java.text.DecimalFormat; import com.jlb.mobile.common.utils.StringUtil; /**
* 单位转换
*
*/
public class UnitUtil2 {
public static float convertG2KG(String numInG) {
if (StringUtil.isEmpty(numInG)) {
return 0f;
} if (!NumberUtil.isRealNumber(numInG)) {
return 0f;
} return new BigDecimal(convertDigital2Str(numInG)).movePointLeft(3).floatValue();
} public static String convertDigital2Str(String number) {
if (StringUtil.isEmpty(number)) {
return null;
}
DecimalFormat format = new DecimalFormat("#0.00");
return format.format(new BigDecimal(number).doubleValue());
} public static float convertCent2Dollar(String money) {
if (StringUtil.isEmpty(money)) {
return 0;
} BigDecimal decimal = new BigDecimal(convertDigital2Str(money));
return decimal.movePointLeft(2).floatValue();
} public static float convertCent2Dollar(float money) {
BigDecimal decimal = new BigDecimal(convertDigital2Str(money));
return decimal.movePointLeft(2).floatValue(); } public static String convertDigital2Str(float number) {
DecimalFormat format = new DecimalFormat("#0.00");
return format.format(number);
} public static String convertKG2GStr(String numInKG) {
if (StringUtil.isEmpty(numInKG)) {
return "0";
} if (!NumberUtil.isRealNumber(numInKG)) {
return null;
} return new BigDecimal(convertDigital2Str(numInKG)).movePointRight(3).toString();
}
}
单位转换类UnitUtil2的更多相关文章
- Revit API单位转换类
用法:txt.Text=UnitConvertC.CovertFromAPI(param.AsDouble());param.Set(UnitConvertC.CovertToAPI(txt.Text ...
- Android 尺寸单位转换和屏幕适配相关
Android 尺寸单位转换和屏幕适配相关 各种尺寸单位的意义 dp: Density-independent Pixels 一个抽象的单元,基于屏幕的物理密度. (dp和dip的意义相同,所以不用区 ...
- spring-boot前端参数单位转换
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import ja ...
- Android屏幕尺寸单位转换
最近在看Android群英传这本书,书中有一节涉及到了,屏幕尺寸与单位.觉得以后可能会用到,做个笔记. PPI(pixels per inch) ,又称为DPI,它是由对角线的像素点数除以屏幕的大小得 ...
- Android原生系统API自带dp、px、sp单位转换
Android系统中自带的Api中可以使用TypedValue进行单位转换 1,调用系统api转换单位 // 获得转换后的px值 float pxDimension = TypedValue.appl ...
- DataTable与DTO对象的简易转换类
在web开发过程中,有时候为了数据传输的方便,比如:后台需要更新前端的ViewModel,此时我们定义一个与前端ViewModel结构一样的DTO对象,从数据层获取数据后,将数据封装成DTO然后序列化 ...
- System.currentTimeMillis()计算方式与时间的单位转换
目录[-] 一.时间的单位转换 二.System.currentTimeMillis()计算方式 一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 ...
- 日期转换类 DateConverter.java
package com.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.D ...
- C# 网络通信大小端转换类
本篇文章主要介绍了"C# 网络通信大小端转换类" using System;namespace Framework.NetPackage.Common { /// <summ ...
随机推荐
- Postgres常用命令之增、删、改、查
增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...
- ABAP CDS - SELECT, association
ABAP CDS - SELECT, association Syntax ... ASSOCIATION [ [min..max] ] TO target [AS _assoc] ON cond_e ...
- Mysql 表转换成 Sqlite表
目前的转换仅仅支持对没有外键的Mysql数据表 准备: 下载安装 Sqlite Expert 软件 一 获取Mysql中的.sql文件,获取过程省略可以直接导出sql文件 二 在Sqlite Expe ...
- java程序——凯撒加密
古罗马皇帝凯撒在打仗时曾经使用过以下方法加密军事情报: 请编写一个程序,使用上述算法加密或解密用户输入的英文字串要求设计思想.程序流程图.源代码.结果截图. 设计思想:输入一个字符串,然后将其中每 ...
- 4G来临,短视频社交分享应用或井喷
因为工作的原因,接触短视频社交应用的时间相对较多,不管是自家的微视,还是别人家的Vine.玩拍.秒拍等,都有体验过.随着时间的推移,我愈发感受到有一股似曾相识的势能正在某个地方慢慢积聚,直到今天我才猛 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目3
2014-04-23 18:10 题目:设计一个点唱机. 解法:英文叫Musical Jukebox.这是点唱机么?卡拉OK么?这种题目实在是云里雾里,又没有交流的余地,我索性用一个vector来表示 ...
- python-使用pip安装第三方库报UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 7: invalid continuation byte 错误解决方案
在python 的安装目录下找到Lib\ntpath.py文件,找到def join(path, *paths):方法,添加如下两行语句: reload(sys) sys.setdefaultenco ...
- 数据库——mysql内置功能(11)
1.视图 视图是一个虚拟表(非真实存在),其本质是(根据SQL语句获取动态的数据集,并未其命名),用户使用时只需使用(名称)即可获取结果集,可以将该结果集当做表来使用 使用视图我们可以把查询过程中的临 ...
- Python全栈工程师(每周总结:3)
ParisGabriel 每天坚持 一天一篇 点个订阅吧 灰常感谢 当个死 ...
- 孤荷凌寒自学python第五十一天初次尝试使用python连接Firebase数据库
孤荷凌寒自学python第五十一天初次尝试使用python连接Firebase数据库 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数据库服 ...