Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

string to accept two characters after point javascript

const translateString = (input) => {
  const [beforeDot, afterDot] = input.split('.')
  if (afterDot) {
    const afterDotTrimmed = afterDot.slice(0, 2)

    if (afterDotTrimmed === '00' || afterDotTrimmed === '0') {
      return beforeDot
    } else {
      return beforeDot + '.' + afterDotTrimmed
    }
  } else {
    return beforeDot
  }
}

translateString('14.0090'); // 14
translateString('14.0'); // 14
translateString('14.90'); // 14.90
translateString('14.96'); // 14.96
translateString('14.9'); // 14.9
translateString('14.'); // 14
translateString('14'); // 14
Comment

PREVIOUS NEXT
Code Example
Javascript :: scss mute warnings 
Javascript :: flutter keep local storage even after is closed 
Javascript :: terminal text length nodejs 
Javascript :: jquery nearest 
Javascript :: add disabled js 
Javascript :: block enter key using jquery 
Javascript :: jsx emmet vscode 
Javascript :: square every digit javascript 
Javascript :: javascript hide all elements except one 
Javascript :: javascript remove all the common value from array 
Javascript :: javascript group by sum array reduce 
Javascript :: react native run on specific emulator 
Javascript :: javascript array remove element 
Javascript :: react native gradient touchable feedback 
Javascript :: save things javascript 
Javascript :: Chamando métodos de utilidade com consign( ) no nodeJs 
Javascript :: js throw error 
Javascript :: jquery get selected checkboxes 
Javascript :: jquery move element 
Javascript :: javascript encode url to decode C# 
Javascript :: javascript uppercase first letter of each word 
Javascript :: Javascript noFill 
Javascript :: object notation and array notation dynamic class binding vuejs 
Javascript :: ClassNotFoundException: com.fasterxml.jackson.core.JsonGenerator 
Javascript :: js regex remove html tags 
Javascript :: xmlhttp js post request 
Javascript :: remove first and last character from string javascript 
Javascript :: Sailsdock 
Javascript :: update node js version ubuntu 
Javascript :: jquery fadein 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =