package com.tidecloud.dataacceptance.common; import java.text.DecimalFormat; /** * @author: chudk * @date: 2017年10月16日 下午4:30:53 */ public class NumUtil { public static Double toFixed2Place(Double num){ if (num == null) { return null; } DecimalFormat df = new DecimalFormat("######0.0"); return Double.valueOf(df.format(num)); } public static void main(String[] args) { Double fixed2Place = NumUtil.toFixed2Place(1112.292d); System.out.println(fixed2Place); } public static byte[] int2bytes(int num) { byte[] b=new byte[4]; //int mask=0xff; for(int i=0;i<4;i++){ b[3-i]=(byte)(num>>>(24-i*8)); } return b; } public static byte[] intToByte(int data, int length){ byte[] bytes = new byte[length]; bytes[0] = (byte)(data >> 8); bytes[1] = (byte)(data & 0xff); return bytes; } public static String byte2String(byte b) { if (b < 10) { return "0" + b; } else { return String.valueOf(b); } } }