浮點數magnitude()是一個浮點類方法,它對浮點值起作用並將其轉換為絕對形式。
用法: float.magnitude()
參數:將轉換為絕對值的浮點值
返回:傳遞的浮點值的絕對值
範例1:
# Ruby program for magnitude() method
# Initializing value
a = -56.23333333
b = -10000.0
c = -(22 + 7.1)
# Printing result
puts "magnitude value of a:#{a.magnitude}\n\n"
puts "magnitude value of b:#{b.magnitude}\n\n"
puts "magnitude value of c:#{c.magnitude}\n\n"
輸出:
magnitude value of a:56.23333333 magnitude value of b:10000.0 magnitude value of c:29.1
範例2:
# Ruby program for magnitude() method
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = -(22 + 7.1) * 4
# Printing result
puts "magnitude value of a:#{a.magnitude}\n\n"
puts "magnitude value of b:#{b.magnitude}\n\n"
puts "magnitude value of c:#{c.magnitude}\n\n"
輸出:
magnitude value of a:111.10000000000001 magnitude value of b:200000.0 magnitude value of c:116.4
相關用法
- Ruby Integer magnitude用法及代碼示例
- Ruby Numeric magnitude()用法及代碼示例
- Ruby Float zero?()用法及代碼示例
- Ruby Float nan?()用法及代碼示例
- Ruby Float quo()用法及代碼示例
- Ruby Float eql()用法及代碼示例
- Ruby Float arg()用法及代碼示例
- Ruby Float modulo()用法及代碼示例
- Ruby Float absolute()用法及代碼示例
- Ruby Float rationalize()用法及代碼示例
- Ruby Float positive()用法及代碼示例
- Ruby Float round()用法及代碼示例
- Ruby Float numerator()用法及代碼示例
- Ruby Float negative()用法及代碼示例
- Ruby Float angle()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby Float magnitude() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。