Skip to content

Commit

Permalink
Added $mol_math_round_expand - round to easy numbers greater then taked.
Browse files Browse the repository at this point in the history
  • Loading branch information
nin--jin committed Mar 2, 2017
1 parent cfa0fd8 commit c639aca
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions math/round/expand/expand.ts
@@ -0,0 +1,16 @@
namespace $ {

export function $mol_math_round_expand( val : number , gap = 1 ) {
if( val === 0 ) return 0

const val_abs = Math.abs( val )
const val_sign = val ? Math.round( val / val_abs ) : 0

const digits = Math.floor( Math.log( val_abs ) / Math.log( 10 ) )
const precission = Math.pow( 10 , digits - gap )
const val_expanded = precission * Math.ceil( val_abs / precission )

return val_sign * val_expanded
}

}

0 comments on commit c639aca

Please sign in to comment.