OpenRefine / OpenRefine/OpenRefine

toString() doesn't cast int to float

Open
#6,852 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.