Difference between revisions of "scala:Convert a String to a Number"

From Progzoo
Jump to: navigation, search
(Created page with "{{topTenTips}} <question height="100" width="150" className="Demo" rows="9" cols="40" lang='scala'> <code>println</code> can be used to output to standard output this works ...")
 
Line 1: Line 1:
 
{{topTenTips}}
 
{{topTenTips}}
 
<question height="100" width="150" className="Demo" rows="9" cols="40" lang='scala'>  
 
<question height="100" width="150" className="Demo" rows="9" cols="40" lang='scala'>  
<code>println</code> can be used to output to standard output this works like <code>System.out.print</code> etc. in Java
+
<code>Integer.parseInt</code> is the static method that you need here.
 +
You have access to all of the java.lang packages such as http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
  
See also
+
See also:
*<code>print</code>
+
*<code>Integer.tryParse</code>
*<code>printf</code>
+
*<code>Double.parse</code>
*<code>println</code>
+
 
<prog>
 
<prog>
 
object Demo {
 
object Demo {
 
   def main(args: Array[String]) {
 
   def main(args: Array[String]) {
     var s:String = "1234";
+
     var s = "1234";
     var i:Int = Integer.parseInt(s);
+
     var i = Integer.parseInt(s);
 
     println(i+1);
 
     println(i+1);
 
   }
 
   }

Revision as of 20:04, 16 February 2015

Integer.parseInt is the static method that you need here. You have access to all of the java.lang packages such as http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)

See also:

  • Integer.tryParse
  • Double.parse


[Font] [Default] [Show] [Resize] [History] [Profile]