From c639acac7311b084ab28503b5d4b2b017e2f480c Mon Sep 17 00:00:00 2001 From: nin-jin Date: Thu, 2 Mar 2017 12:15:10 +0300 Subject: [PATCH] Added $mol_math_round_expand - round to easy numbers greater then taked. --- math/round/expand/expand.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 math/round/expand/expand.ts diff --git a/math/round/expand/expand.ts b/math/round/expand/expand.ts new file mode 100644 index 0000000000..93c955fb65 --- /dev/null +++ b/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 + } + +}