@ Pure public static SpaceUnit getSmallestUnit ( double amount , SpaceUnit unit ) { final double meters = toMeters ( amount , unit ) ; double v ; final SpaceUnit [ ] units = SpaceUnit . values ( ) ; SpaceUnit u ; for ( int i = units . length - 1 ; i >= 0 ; -- i ) { u = units [ i ] ; v = Math . floor ( fromMeters ( meters , u ) ) ; if ( v > 0. ) { return u ; } } return unit ; }
Compute the smallest unit that permits to have a metric value with its integer part positive .