sanchis / Madhardware

The purpose of the project is to be able to compare hardware products between different online stores in Spain. The idea is to be able to get the best price for the product you are looking for.

Home Page:https://madhardware.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use intl to format price base on region

sanchis opened this issue · comments

Use a advanced feature Intl to format correctly price

const formatter = new Intl.NumberFormat('es-ES', {
  style: 'currency',
  currency: 'EUR'
})
return formatter.format(price)

The original price is 1.100,95 the error seems to be on parseFloat function
image

Numbers to test.

Price Expected price
1021,30 1021,30 €
1029 1029 €
1.100,95 1100,95 €
1149.0 1149 €
27.49 27,49 €
44.94 44,94 €

Use intl tool to generate the correct format to prices.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

Create a common function to format all prices from all parser shops.