OpenRefine / OpenRefine/OpenRefine
toString() doesn't cast int to float
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 12k
- Forks
- 2.2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 27
Description
I had a column in my projects with numerical values (imported as strings) that I wanted to serialise into a standard format. I used value.toNumber().toString("%.4f") and found that this mostly worked but it fell over with an error when the source value was represented as an integer. So it seems passing an integer into the format "%f" gives an error:
toString(1,"%f)
Error: java.util.IllegalFormatConversionException: f != java.lang.Long
The workaround is to force a cast to float by multiplying the value by 1.0, but I think this feels counter-intuitive. Given that OR only gives a single function toNumber() (not toFloat() and toInteger() ), I think it's appropriate for the toString function to apply whatever type casting is required for the format.
OpenRefine version 3.8.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the toNumber() and toString("%f") entry points described in the issue, using an integer source value. Then trace their implementation and existing tests; done means integer values format successfully as floating-point output and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100