Why float64 value is printed wrongly?


I have created a float64 variable and stored the value in it.

Now I tried to print the value but it displays some other value.

package main

import (
func main() {
	var a float64
	a = 9999999999999999999999999999.99
	fmt.Printf("%f\n", a)
	var b float64
	b = 99999999999999999999
	fmt.Printf("%f\n", b)
	var c float64
	c = 9999999999999999999999999
	fmt.Printf("%f\n", c)

The output of the program is different.

I think I am doing something wrong. Please Guide me on this issue.


Floating-point numbers are an approximation.

Why don’t my numbers add up?

IEEE 754

What Every Computer Scientist Should Know About Floating-Point Arithmetic

IEEE Standard 754 for Binary Floating-Point Arithmetic

The Go Programming Language Specification

Floating-point literals

Numeric types

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.