单位转换类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 ...
随机推荐
- [BZOJ2243][SDOI2011]染色(树链剖分)
[传送门] 树链剖分就行了,注意线段树上颜色的合并 Code #include <cstdio> #include <algorithm> #define N 100010 # ...
- python-12正则表达式
import re #re.search方法 re.search 扫描整个字符串并返回第一个成功的匹配. re.match('com', 'www.runoob.com') #匹配失败 None re ...
- Ubuntu下配置LAMP + PhpStorm
本文仅作为一个记录,以下配置在Ubuntu 14.10 64-bit上验证通过. 安装Apache 2:sudo apt-get install apache2 安装成功能够后,通过浏览器访问loca ...
- Javascript Step by Step - 04
前言 本篇主要讨论jQuery的常用的若干操作.为了能直观的显示操作的结果,首先建立一个html文件,内容如下: <!DOCTYPE html> <html> <head ...
- POJ 3461 Oulipo(字符串hash)
题目链接 字符串hash判断字符串是否相等. code #include<cstdio> #include<algorithm> #include<cstring> ...
- erlang节点互通查看
在局域网内部,一般用短节点名来完成短节点的全联通. 全联通的前提之一是cookie要相同,cookie记录在一个文件中. 对于同一个物理机上的两个erlang节点,不用其他配置就可以全 ...
- APP测试用例要考虑的一些方面
安装与卸载:●应用是否可以在IOS不同系统版本或android不同系统版本上安装(有的系统版本过低,应用不能适配)●软件安装后是否可以正常运行,安装后的文件夹及文件是否可以写到指定的目录里.●安装过程 ...
- QA面试题:之一(中英文题目、难度:简单)
QA面试题:之一(中英文题目.难度:简单)
- Canvas 剪切图片
/** * 剪切图像 */ function initDemo8(){ var canvas = document.getElementById("demo8"); if (!ca ...
- 孤荷凌寒自学python第五十三天使用python写入和修改Firebase数据库中记录
孤荷凌寒自学python第五十三天使用python写入和修改Firebase数据库中记录 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数 ...