Home > Software design >  How to fix this code? Enable the java parseDouble in scalafx program
How to fix this code? Enable the java parseDouble in scalafx program

Time:11-27

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

CodePudding user response:

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

CodePudding user response:

In this case, I first thought of using switch, although it is just as long.

  • Related