Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Bad conversion - dropped method when calling #55

dnadolny opened this Issue · 4 comments

2 participants


Converting the Java double a = Double.valueOf("1.0"); gives the scala val a = "1.0". It should be val a = Double.valueOf("1.0").


Scala's own Double doesn't have it$

Is there an idiomatic Scala way to parse a String to Double? If not, then java.lang.Double.valueOf(arg) is the solution.

@timowest timowest referenced this issue from a commit
@timowest timowest #55 Add test 29d0617

I think the idiomatic Scala way would be arg.toDouble, using the implicit conversion to StringOps. StringOps.toDouble delegates to java.lang.Double.parseDouble(arg), which returns a double primitive.
This is different behavior from java.lang.Double.valueOf(arg), which returns the equivalent of new Double(parseDouble(arg)). You can see that by comparing (Java):

System.out.println(Double.valueOf("1.0") == Double.valueOf("1.0")); //false
System.out.println(Double.parseDouble("1.0") == Double.parseDouble("1.0")); //true

Since it's hard to get the Java behavior in Scala (you'd have to call valueOf, but worse than that is you would have to change all instances of == to eq to regain the reference equality check, which is only possible if you're converting all the code at once).
I think the best solution is to make it arg.toDouble, and let this be a "gotcha" with conversion, if anyone was relying on the Java behavior.


Thanks for the suggestion. For now the solution is the same as #54


Released in 0.3.1

@timowest timowest closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.