private double calcNiceNumber ( final double RANGE , final boolean ROUND ) { final double EXPONENT = Math . floor ( Math . log10 ( RANGE ) ) ; // exponent of range final double FRACTION = RANGE / Math . pow ( 10 , EXPONENT ) ; // fractional part of range // nice, rounded fraction final double NICE_FRACTION ; if ( ROUND ) { if ( FRACTION < 1.5 ) { NICE_FRACTION = 1 ; } else if ( FRACTION < 3 ) { NICE_FRACTION = 2 ; } else if ( FRACTION < 7 ) { NICE_FRACTION = 5 ; } else { NICE_FRACTION = 10 ; } } else { if ( FRACTION <= 1 ) { NICE_FRACTION = 1 ; } else if ( FRACTION <= 2 ) { NICE_FRACTION = 2 ; } else if ( FRACTION <= 5 ) { NICE_FRACTION = 5 ; } else { NICE_FRACTION = 10 ; } } return NICE_FRACTION * Math . pow ( 10 , EXPONENT ) ; }
Returns a nice number approximately equal to the range . Rounds the number if ROUND == true . Takes the ceiling if ROUND = false .