mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-04 01:50:17 +08:00
43 lines
986 B
Java
43 lines
986 B
Java
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
|
||
* @param amount
|
||
* @return
|
||
*/
|
||
public static String formatAmount(String amount) {
|
||
//保留2位小数
|
||
double d = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||
//不足两位则补0
|
||
DecimalFormat decimalFormat = new DecimalFormat("0.00#");
|
||
return decimalFormat.format(d);
|
||
}
|
||
|
||
/**
|
||
* 格式化数字 保留两位小数,不足补0
|
||
* @param amount
|
||
* @return
|
||
*/
|
||
public static String formatAmount(BigDecimal amount) {
|
||
return formatAmount(amount.toString());
|
||
}
|
||
}
|