zeroclickinfo-spice
zeroclickinfo-spice copied to clipboard
Currency: Round to number of significant figures instead of number of decimal places.
Description of new Instant Answer, or changes
Currently the Currency and Cryptocurrency IAs are rounding to a certain number of digits, instead of rounding to a certain number of significant figures. This causes conversions to be inaccurate.
For example, https://duckduckgo.com/?q=0.1+usd+to+eur&ia=currency currently gives 0.09 EUR
, but should be giving 0.088 EUR
. (Conversion as of Mid-Market Rates: 2018-12-08 at 17:00 UTC)
For the Cryptocurrency IA, https://duckduckgo.com/?q=1+ftc+to+usd&ia=cryptocurrency currently gives 0.02 USD
, but should be giving 0.018 USD
. (Conversion as of Market Rates: 2018-12-09 at 12:07 UTC)
This PR fixes these issues, and also fixes the issue in the inverse direction. It does so by replacing toFixed()
with toPrecision()
. toPrecision
can sometimes return a number in its exponential format (e.g. 1200 = 1.2e+3), but the HTML5 input field with type number
will display these correctly.
Related Issues and Discussions
Fixes #3537
People to notify
@moollaza
Instant Answer Page: https://duck.co/ia/view/currency
Currency Conversion
Description: Currency Convertor provided by XE.com
Example Query: convert 499 usd to cad, cad to usd, cny?
Tab Name: Currency
Source:
These are the important fields from the IA page. Please check these for errors or missing information and update the IA page
This is an automated message which will be updated as changes are made to the IA page
@pjhampton do you remember why we chose decimal places? I feel like it was it to prevent the strings from being too long?
@moollaza it seemed to be a search industry standard and a UX decision. However, I'm not opposed to this - just needs cross browser testing.
There was also an issue with firefox and using the number input type (reported by Andrey, if I remember correctly). This is why we didn't use a type="number"
on the calculator either.