1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package com.huimv.produce.utils;
- import org.springframework.stereotype.Component;
- import java.text.NumberFormat;
- /**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
- @Component
- public class MathUtil {
- public String formatBit(float num, int bit) {
- // 创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- // 设置精确到小数点后2位
- numberFormat.setMaximumFractionDigits(bit);
- return numberFormat.format(num);
- }
- public String formatBit(float num) {
- return String.valueOf(num);
- }
- //计算比率
- public String countRate(float num, int bit) {
- // 创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- // 设置精确到小数点后2位
- numberFormat.setMaximumFractionDigits(bit);
- return numberFormat.format(num * 100);//所占百分比
- }
- //计算占比
- public String countRate(float num, float total,int bit) {
- // 创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- // 设置精确到小数点后2位
- numberFormat.setMaximumFractionDigits(bit);
- //所占百分比
- return numberFormat.format((float) num/ (float)total* 100);
- }
- //格式化
- public String format(float num, int bit) {
- // 创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- // 设置精确到小数点后2位
- numberFormat.setMaximumFractionDigits(bit);
- return numberFormat.format(num * 100);//所占百分比
- }
- //格式化
- public String format(float num, float total,int bit) {
- // 创建一个数值格式化对象
- NumberFormat numberFormat = NumberFormat.getInstance();
- // 设置精确到小数点后2位
- numberFormat.setMaximumFractionDigits(bit);
- //所占百分比
- return numberFormat.format((float) num/ (float)total* 100);
- }
- }
|