Open In App

Scala Char toFloat() method with example

The toFloat() method is utilized to convert a stated character into float or its ASCII value of type float.

Method Definition: def toFloat: Float



Return Type: It returns Float or ASCII value of the corresponding letter of type float.

Example: 1#




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

Output:

65.0

Example: 2#




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

Output:
55.0

Article Tags :