Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript format currency

function formatToCurrency(amount){
    return (amount).toFixed(2).replace(/d(?=(d{3})+.)/g, '$&,'); 
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
Comment

javascript format number as currency

const formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',
  minimumFractionDigits: 2
})

formatter.format(1000) // "$1,000.00"
formatter.format(10) // "$10.00"
formatter.format(123233000) // "$123,233,000.00"
Comment

function js format money

// Create our number formatter.
var formatter = new Intl.NumberFormat('en-US', {
  style: 'currency',
  currency: 'USD',

  // These options are needed to round to whole numbers if that's what you want.
  //minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
  //maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});

formatter.format(2500); /* $2,500.00 */
Comment

javascript currency format

const formatter = new Intl.NumberFormat('en-ID', {
  style: 'currency',
  currency: 'IDR'
}).format(10000000)
.replace(/[IDR]/gi, '')
.replace(/(.+d{2})/, '')
.trimLeft()


console.log(`Rp ${formatter}`)
Comment

PREVIOUS NEXT
Code Example
Javascript :: react router go rprevious page 
Javascript :: how to remove identical string in javascript 
Javascript :: make first letter capital 
Javascript :: how to put text in the center react native 
Javascript :: convert string time to time in javascript 
Javascript :: react native text ellipsis 
Javascript :: window.location.search get parameters react 
Javascript :: javascript string search second occurrence 
Javascript :: how to call rest api with the useeffect hook in react 
Javascript :: react use same useState for multiple inputs 
Javascript :: for element in string js 
Javascript :: decode morse code js 
Javascript :: react toastify does not have design 
Javascript :: using map in useeffect 
Javascript :: getting days difference with moment js 
Javascript :: javascript sort array of objects by key value 
Javascript :: chess 
Javascript :: jquery get select name value 
Javascript :: js conditional object key 
Javascript :: create file if not exists nodejs 
Javascript :: append element in a div as first child 
Javascript :: addEventListener call only once 
Javascript :: if back react 
Javascript :: javascript clear radio button 
Javascript :: javascript cookies store object 
Javascript :: get number of days between two dates mongodb query 
Javascript :: js enum 
Javascript :: iframe reload parent page 
Javascript :: get all cookies 
Javascript :: reversed array loop 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =