-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfloat.rb
More file actions
43 lines (29 loc) · 728 Bytes
/
float.rb
File metadata and controls
43 lines (29 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require_relative 'helpers'
header('Float')
headline('Declaration')
puts 1.234 # 1.234
puts 1.30e3 # 1300.0
puts 10.25 + 32 # 42.25
puts 32 + 10.25 # 42.25
headline('Methods')
# absolute value
puts -15.24.abs # 15.24
# rounding
puts 3.4.ceil # 4
puts 3.6.floor # 3
puts 4.2.round # 4
puts 4.5.round # 5
p 8.coerce(6) # [6, 8]
p 6.coerce(8.5) # [8.5, 6.0]
p 8.5.coerce(6) # [6.0, 8.5]
p 13.divmod(5) # [2, 3]
headline('---------')
puts 7.4.integer? # false
puts 7.integer? # true
headline('---------')
puts 6.8.negative? # false
puts -6.8.negative? # true
headline('---------')
p 2.nonzero? # false
p 0.nonzero? # nil
p 0.0.nonzero? # nil