Skip to content
Related Articles

Related Articles

Improve Article

Scala Float abs() method with example

  • Last Updated : 29 Oct, 2019
Geek Week

The abs() method is utilized to return the absolute value of the given integer value. The absolute value of any number is the magnitude of that number i.e, without any sign.

Method Definition: def abs: Float

Return Type: It return the absolute value of the given integer value.

Example #1:




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

Example #2:




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



My Personal Notes arrow_drop_up
Recommended Articles
Page :