public static final double calcNiceNumber ( final double RANGE , final boolean ROUND ) { double niceFraction ; double exponent = Math . floor ( Math . log10 ( RANGE ) ) ; // exponent of range double fraction = RANGE / Math . pow ( 10 , exponent ) ; // fractional part of range if ( ROUND ) { if ( Double . compare ( fraction , 1.5 ) < 0 ) { niceFraction = 1 ; } else if ( Double . compare ( fraction , 3 ) < 0 ) { niceFraction = 2 ; } else if ( Double . compare ( fraction , 7 ) < 0 ) { niceFraction = 5 ; } else { niceFraction = 10 ; } } else { if ( Double . compare ( fraction , 1 ) <= 0 ) { niceFraction = 1 ; } else if ( Double . compare ( fraction , 2 ) <= 0 ) { niceFraction = 2 ; } else if ( Double . compare ( fraction , 5 ) <= 0 ) { niceFraction = 5 ; } else { niceFraction = 10 ; } } return niceFraction * Math . pow ( 10 , exponent ) ; }
Returns a niceScaling number approximately equal to the range . Rounds the number if ROUND == true . Takes the ceiling if ROUND = false .