How to fix this code? Enable the java parseDouble in scalafx program

56 views Asked by At

I am a new learner of scala and I am coding a simple scalafx calculator and now I face a problem. I cannot find another suitable code to replace the parseDouble. I know the parseDouble is the member of java double, not scala double. I just put the code here to express my thoughts. Can someone help me to fix the code? enter image description here

1

There are 1 answers

0
jwvh On

You can invoke the Java parser directly...

val n1 = java.lang.Double.parseDouble(display.getText())

...or you can use the Scala .toDouble.

val n1 = display.getText().toDouble