NumUtil.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.tidecloud.dataacceptance.common;
  2. import java.text.DecimalFormat;
  3. /**
  4. * @author: chudk
  5. * @date: 2017年10月16日 下午4:30:53
  6. */
  7. public class NumUtil {
  8. public static Double toFixed2Place(Double num){
  9. if (num == null) {
  10. return null;
  11. }
  12. DecimalFormat df = new DecimalFormat("######0.0");
  13. return Double.valueOf(df.format(num));
  14. }
  15. public static void main(String[] args) {
  16. Double fixed2Place = NumUtil.toFixed2Place(1112.292d);
  17. System.out.println(fixed2Place);
  18. }
  19. public static byte[] int2bytes(int num)
  20. {
  21. byte[] b=new byte[4];
  22. //int mask=0xff;
  23. for(int i=0;i<4;i++){
  24. b[3-i]=(byte)(num>>>(24-i*8));
  25. }
  26. return b;
  27. }
  28. public static byte[] intToByte(int data, int length){
  29. byte[] bytes = new byte[length];
  30. bytes[0] = (byte)(data >> 8);
  31. bytes[1] = (byte)(data & 0xff);
  32. return bytes;
  33. }
  34. public static String byte2String(byte b) {
  35. if (b < 10) {
  36. return "0" + b;
  37. } else {
  38. return String.valueOf(b);
  39. }
  40. }
  41. }