java - Using double up to two decimal places -
i want use double 2 decimal places. i.e. stored upto 2 decimal places, if 2 double values compared comparison should based on first 2 decimal places. how achieve such thing? mean storing, comparison, based on 1st 2 decimal places. remaining places may different, greater than, less than, doesn't matter.
edit values arent large. 0 5000 maximum. have multiply cos a, sin a lot of times, value of keeps changing during course of program.
edit in program car moving @ particular speed, 12 m/s. after every few minutes, car changes direction, in chooses new angle , starts moving in straight line along direction. everytime moves, have find out x , y position on map. currentx+velocity*cos , currenty+velocity*sin a. since happens often, there lot of cumulative error on time. how avoid that?
comparing floating point values equality should use form of delta/epsilon comparison:
if (abs(value1 - value2) < 0.01 ) { // considered equal 2 decimal places }
Comments
Post a Comment