我想显示两位小数,并以更合适的方式显示没有括号的值
ScanRecord scanRecord = result.getScanRecord();
assert scanRecord != null;
byte[] puckData = scanRecord.getManufacturerSpecificData(0x0590);
assert puckData != null;
double lightValue = Double.parseDouble(
Arrays.toString(new byte[]{puckData[0]}).replace("[", "").replace("]", ""));
double tempValue = Double.parseDouble(
Arrays.toString(new byte[]{puckData[1]}).replace("[", "").replace("]", ""));
double batteryValue = Double.parseDouble(
Arrays.toString(new byte[]{puckData[2]}).replace("[", "").replace("]", ""));
答案 0 :(得分:0)
double lightValue = .0;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(lightValue));
它将打印0.00
答案 1 :(得分:0)
试试这个
DecimalFormat df = new DecimalFormat(".##");
Log.d("","kilobytes (DecimalFormat) : " + df.format(123.678));
它将返回: 123.68