JSFiddle - React, Tailwind, and code Playground

by kentaromiura

JavaScript

function Normalize(number, separator){
    separator = separator || '.'
    
    var result = '' +number,
        test = result.split(separator)
    
    if(test.length < 2){
        test.push('00');
    } 
    
    var decimals = test[1].split('')
        decimals.push('0','0')
    
    return test[0] + separator + decimals.slice(0,2).join('')
}

alert(Normalize(0))
alert(Normalize(1))
alert(Normalize(1.1))
alert(Normalize(0.00))
alert(Normalize(1.20))
alert(Normalize(11.22))
alert(Normalize(11.222))