Skip to content

Commit

Permalink
add doc for float number
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Dec 12, 2023
1 parent 340371b commit 834e29f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 108-Floating-Point-Numbers/numbers.gop
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
// There are two floating point types in Go+, float32 and float64
// Floating point literals have a default type of float64.
//
// A floating-point number cannot represent a decimal value exactly. Do not use them to
// represent money or any other value that must have an exact decimal representation!
//
// While you can use == and != to compare floats, don’t do it. Due to the
// inexact nature of floats, two floating point values might not be equal when you
// think they should be. Instead, define a minimum allowed variance and see if the
// difference between two floats is less than that. This minimum value (sometimes
// called epsilon) depends on what your accuracy needs are;
//
// 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).

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

0 comments on commit 834e29f

Please sign in to comment.