Seven_segment可能的损失精度

时间:2013-10-07 12:11:44

标签: java numbers type-conversion precision

这是我显示七段的代码,但是在此代码中有一个问题可能会导致精度损失。请帮我解决这个问题

 void ComputeDisplayValue(String value){
    SevenSeg.NumDigits = 5;
    long temp = Long.parseLong(value.substring(0,1));
    SevenSeg.DisplayValue[0] = SevenSeg.SegmentMap[ temp ];
    temp = Long.parseLong(value.substring(1,2));
    SevenSeg.DisplayValue[1] = SevenSeg.SegmentMap[ temp ];
    temp = Long.parseLong(value.substring(2,3));
    SevenSeg.DisplayValue[2] = SevenSeg.SegmentMap[ temp ];
    temp = Long.parseLong(value.substring(3,4));
    SevenSeg.DisplayValue[3] = SevenSeg.SegmentMap[ temp ];
    temp = Long.parseLong(value.substring(4,5));
    SevenSeg.DisplayValue[4] = SevenSeg.SegmentMap[ temp ];*/
    /* Suppress leading zero in 12 hour mode */            
  }

1 个答案:

答案 0 :(得分:0)

将所有longLong分别更改为intInteger

数组索引是整数,它们不能长。因此,当您执行

时出错

SevenSeg.SegmentMap[temp]