Open In App

Scala Float toFloat() method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The toFloat() method is utilized to converted the specified number into float value.

Method Definition: (Number).toFloat

Return Type: It returns the converted float value.

Example #1:




// Scala program of Float toFloat()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying toFloat method
        val result = (9).toFloat
          
        // Displays output
        println(result)
      
    }


Output:

9.0

Example #2:




// Scala program of Float toFloat()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying toFloat method
        val result = (0).toFloat
          
        // Displays output
        println(result)
      
    }


Output:

0.0

Example #3:




// Scala program of Float toFloat()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying toFloat method
        val result = (4.7).toFloat
          
        // Displays output
        println(result)
      
    }


Output:

4.7


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads