Skip to content

Commit 834e29f

Browse files
committed
add doc for float number
1 parent 340371b commit 834e29f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1+
// There are two floating point types in Go+, float32 and float64
2+
// Floating point literals have a default type of float64.
3+
//
4+
// A floating-point number cannot represent a decimal value exactly. Do not use them to
5+
// represent money or any other value that must have an exact decimal representation!
6+
//
7+
// While you can use == and != to compare floats, don’t do it. Due to the
8+
// inexact nature of floats, two floating point values might not be equal when you
9+
// think they should be. Instead, define a minimum allowed variance and see if the
10+
// difference between two floats is less than that. This minimum value (sometimes
11+
// called epsilon) depends on what your accuracy needs are;
12+
//
13+
// Float literals can also be declared as a power of ten and dividing a float variable set to 0 by 0 returns NaN (Not a Number).
114

15+
f0 := 42e1 // 420
16+
f1 := 123e-2 // 1.23
17+
f2 := 456e+2 // 45600
18+
f3 := 1.0
19+
println(f0, f1, f2, f3, f0/0)

0 commit comments

Comments
 (0)