单位转换类UnitUtil2

mac2022-06-30  132

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(); } }

 

转载于:https://www.cnblogs.com/xinmengwuheng/p/5886329.html

相关资源:百度百科1-3000
最新回复(0)