mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
update huifu
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.jsowell.common.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class AdapayUtil {
|
||||
public static void main(String[] args) {
|
||||
String amount = "1110.5309";
|
||||
String s = formatAmount(amount);
|
||||
System.out.println(s);
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(amount);
|
||||
String s2 = formatAmount(bigDecimal);
|
||||
System.out.println(s2);
|
||||
}
|
||||
|
||||
// 格式化数字 保留两位小数,不足补0
|
||||
public static String formatAmount(String amount) {
|
||||
//保留2位小数
|
||||
double score = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
//不足两位则补0
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.00#");
|
||||
return decimalFormat.format(score);
|
||||
}
|
||||
|
||||
public static String formatAmount(BigDecimal amount) {
|
||||
return formatAmount(amount.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user