Crazy Horse
asked on
currency formatter
On my localhost I am using this function to give me a value in currency format
const currencyFormatter = new Intl.NumberFormat("en-ZA", {
style: "currency",
currency: "ZAR",
minimumFractionDigits: 2,
});
This works as expected. However, after deploying to Heroku instead of the output being:R 6,500.00
it is ZAR 6,500.00
is this a heroku thing or issue with the code?
whats is the code that prints/uses this format?
I am getting
on my Win 10 Ent - Chrome / 64 Bit
https://jsfiddle.net/HainKurt/m73v5qyt/
const number = 123456.789;
const currencyFormatter = new Intl.NumberFormat("en-ZA", {
style: "currency",
currency: "ZAR",
minimumFractionDigits: 2,
});
console.log(currencyFormatter.format(number));
R 123 456,79on my Win 10 Ent - Chrome / 64 Bit
https://jsfiddle.net/HainKurt/m73v5qyt/
@HainKurt: Heroku is a multi-language/system. Especially supporting node.js. Thus my guess for the Heroku installation.
ICU Locale “English (South Africa)” (en_ZA)
https://www.localeplanet.com/icu/en-ZA/index.htmllooks like, these are using some local files (ICU Fıles) for all those formatting...
if you have wrong info, you need to update whatever you use...
browser/node.js/app/library...
ASKER
@HainKurt, it works fine on my local Node.js installation, it is just on the Heroku server that it is doing this but I don't know how to resolve the issue. I am on the Heroku free tier and I don't see anywhere or know how to fix it so I was wondering if there is a workaround with the javascript code I posted or advice on how to sort it out on Heroku.
they need to update some libraries I guess...
https://www.localeplanet.com/java/en-ZA/index.html
anyways, you can replace "ZAR" with "R" for temp fix...
https://www.localeplanet.com/java/en-ZA/index.html
anyways, you can replace "ZAR" with "R" for temp fix...
currencyFormatter.format(number).replace("ZAR", "R")
replace :
currency: "ZAR",
by :
currency: "R",
or anything else, for example :
currency: "AIR",
to confirm it use ZAR as it doesn't find the currency until you install it
currency: "ZAR",
by :
currency: "R",
or anything else, for example :
currency: "AIR",
to confirm it use ZAR as it doesn't find the currency until you install it
@HainKurt, you still want to run this on your computer in a browser instead on Heroku with NodeJS
@leakim971
I thought this is js and will run on browser/clients...
even if it runs on that server only, changing currency probably will not work,
they all run the same specs...
thats why, I suggested, get whatever it returns, and do a string replace to fix it...
if updating libraries is not an option...
I thought this is js and will run on browser/clients...
even if it runs on that server only, changing currency probably will not work,
they all run the same specs...
thats why, I suggested, get whatever it returns, and do a string replace to fix it...
if updating libraries is not an option...
I did some test on my pc
and currency format accepted is 3 char
full list is here
https://www.currency-iso.org/en/home/tables/table-a1.html
but you can use any other 3 letter code
if it is less than 3, or any non alpha char, it is not accepted...
this is standard, no matter where it is run...
so, currency="R" will not work
but using any 3 letter code,
like currency="ANY" and then replace "ANY" with "R" will work...
and currency format accepted is 3 char
full list is here
https://www.currency-iso.org/en/home/tables/table-a1.html
but you can use any other 3 letter code
if it is less than 3, or any non alpha char, it is not accepted...
this is standard, no matter where it is run...
so, currency="R" will not work
but using any 3 letter code,
like currency="ANY" and then replace "ANY" with "R" will work...
Guys, your mixing the currency code with the currency symbol.
When you see the currency code instead of the symbol in the front-end, then this normally means, that the system has no lookup for the symbol and is using the code. Or the the localization table is not complete and it contains as symbol the code.
Doing a replace on the currency code is plastic surgery at the wrong point.
You need to look into the localization system. That's work, but you need to do it, to fully understand it.
When you see the currency code instead of the symbol in the front-end, then this normally means, that the system has no lookup for the symbol and is using the code. Or the the localization table is not complete and it contains as symbol the code.
Doing a replace on the currency code is plastic surgery at the wrong point.
You need to look into the localization system. That's work, but you need to do it, to fully understand it.
ASKER
@leakim971, I did see that as well. I am already using en-ZA. Like I said, it works as expected on my local machine but not on Heroku, so something could be wrong there but I have no idea how to fix it on Heroku.
As I already wrote, the fact that it works on your machine means in this case that the code is fine, It is a setup or configuration issue of Heroku. The bug as indicated by leakim971 in metabase confirms this in my opinion.
Thus: I would talk the providers technical team,
Thus: I would talk the providers technical team,
here the file : https://analytics.utah.gov/bi/lib/ecma402/0.2.3-dev/cldr/en-ZA/currencies.json
It look fine
It seems by default NodeJS don't come with all the locales
you need to install the full-icu package : https://github.com/unicode-org/full-icu-npm
It look fine
It seems by default NodeJS don't come with all the locales
you need to install the full-icu package : https://github.com/unicode-org/full-icu-npm
npm install full-icu
ASKER
Thanks leakim971, I will give that a try
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
So you should look into the localization handling of Heroku and how it interacts with the front-ends.