witnet-rust icon indicating copy to clipboard operation
witnet-rust copied to clipboard

Error when parsing floats with commas

Open girazoki opened this issue 4 years ago • 6 comments

Source: [https://www.chards.co.uk/data/update-prices?full=false&currency=eur]

Script:

const chards = new Witnet.Source("https://www.chards.co.uk/data/update-prices?full=false&currency=eur")
  .parseMapJSON()
  .getMap("gold")
  .getFloat("gram")
  .multiply(1000)
  .round()

Error:

RadError cannot be converted to RadonError but it should, because it is needed for the tally result. Message: None. Inner: Some(ParseFloat { message: "invalid float literal" })

girazoki avatar Mar 30 '20 15:03 girazoki

That's not supported, a simple workaround would be to String.replace(",", "")

tmpolaczyk avatar Mar 31 '20 13:03 tmpolaczyk

That's not supported, a simple workaround would be to String.replace(",", "")

If we only had a .replace RADON method...

aesedepece avatar Mar 31 '20 13:03 aesedepece

@aesedepece Would it make sense to have a getFloat RADON function that allows to specify thousand and decimal separators for greater parsing flexibility? Example getFloat("gram", thousand=" ", decimal=",") for a number 111 111,111.

drcpu-github avatar Sep 30 '20 10:09 drcpu-github

Could we create a WIP for this? @tmpolaczyk @lrubiorod

Tommytrg avatar Dec 21 '21 11:12 Tommytrg

We could

tmpolaczyk avatar Dec 21 '21 11:12 tmpolaczyk

Yes, we could

aesedepece avatar Dec 27 '21 17:12 aesedepece

This was solved by #2235, now about to be released inside 1.6 as per WIP-0024.

aesedepece avatar Feb 15 '23 11:02 aesedepece