You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although the above is not incorrect, per se, it gives precedence to currency.exponent whereas I think it should give precedence to the user supplied scale . This is because when the caller calls the function with a scale, the caller would expect the supplied scale to be applied first and then if that fails, then try and apply the default scale of the currency
So I propose,
functiondineroFromFloat({amount: float, currency, scale }){// NOT const factor = currency.base ** currency.exponent || scale;// I propose it should beconstfactor=currency.base**scale||currency.exponent;// OR// const factor = currency.base ** (scale ?? currency.exponent) ;constamount=Math.round(float*factor);returndinero({ amount, currency, scale });}
The text was updated successfully, but these errors were encountered:
quophyie
changed the title
Documentation regarding creation of Dinero objects from floats
Documentation regarding creation of Dinero objects from floats in Dinero V2
Oct 25, 2023
In FAQ docs in Dinero v2-alpha i.e (https://v2.dinerojs.com/docs/faq/how-can-i-create-dinero-objects-from-floats, follows from #58), the code is written as follows
Although the above is not incorrect, per se, it gives precedence to
currency.exponent
whereas I think it should give precedence to the user suppliedscale
. This is because when the caller calls the function with a scale, the caller would expect the supplied scale to be applied first and then if that fails, then try and apply the default scale of the currencySo I propose,
The text was updated successfully, but these errors were encountered: