Commit f0f9112d764caecc99353d0dcdc5d32dd24332e3
1 parent
51cac3b76d
Exists in
master
and in
6 other branches
mathutil add
Showing 1 changed file with 38 additions and 0 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java
View file @
f0f9112
1 | +package com.lyms.platform.operate.web.utils; | |
2 | + | |
3 | +import java.text.DecimalFormat; | |
4 | + | |
5 | +/** | |
6 | + * @Author: litao | |
7 | + * @Date: 2017/4/20 0020 14:40 | |
8 | + * @Version: V1.0 | |
9 | + */ | |
10 | +public class MathUtil { | |
11 | + | |
12 | + /** | |
13 | + * 整数相除 保留六位小数 | |
14 | + * @param a | |
15 | + * @param b | |
16 | + * @return | |
17 | + */ | |
18 | + public static String division(int a ,int b){ | |
19 | + float num =(float)a/b; | |
20 | + DecimalFormat df = new DecimalFormat("0.000000"); | |
21 | + return df.format(num); | |
22 | + } | |
23 | + | |
24 | + public static String division(String a ,String b){ | |
25 | + return division(Integer.valueOf(a), Integer.valueOf(b)); | |
26 | + } | |
27 | + | |
28 | + /** | |
29 | + * 格式化dubbo类型数据 保留2位 | |
30 | + * @param d | |
31 | + * @return | |
32 | + */ | |
33 | + public static String doubleFormat(Double d) { | |
34 | + DecimalFormat df = new DecimalFormat("######0.00"); | |
35 | + return df.format(d); | |
36 | + } | |
37 | + | |
38 | +} |