JSFiddle - React, Tailwind, and code Playground
by edskeizer
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/1.5.3/numeral.min.js"></script>
CoffeeScript
format_currency = (number, leading_euro = true) ->
if leading_euro
numeral(number).format '$0,0.00'
else
numeral(number).format '0,0.00'
calculate_vat = (excl, vat, incl, percentage = 21, leading_euro = true) ->
if excl? and $.isNumeric(excl)
incl = excl * ((100+percentage)/100)
obj =
vat: format_currency(incl - excl, leading_euro)
incl: format_currency(incl, leading_euro)
else if vat? and $.isNumeric(vat)
excl = vat / (percentage / 100)
obj =
excl: format_currency(excl, leading_euro)
incl: format_currency(vat + excl, leading_euro)
else if incl? and $.isNumeric(incl)
excl = incl / ((percentage+100)/100)
obj =
excl: format_currency(excl, leading_euro)
vat: format_currency(incl - excl, leading_euro)
obj
$ ->
numeral.language 'nl-nl',
delimiters:
thousands: '.'
decimal: ','
abbreviations:
thousand: 'k'
million: 'mln'
billion: 'mrd'
trillion: 'bln'
ordinal: (number) ->
remainder = number % 100
if number != 0 and remainder <= 1 or remainder == 8 or remainder >= 20 then 'ste' else 'de'
currency: symbol: '€ '
numeral.language "nl-nl"
console.log calculate_vat null,null,10