I got a 3.1399968427..........

This is a discussion on I got a 3.1399968427.......... within the C++ Programming forums, part of the General Programming Boards category; it is strange that I named a float variable and value it with 3.14, but it show me a 3.1399968427..........in ...

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Question I got a 3.1399968427..........

    it is strange that I named a float variable and value it with 3.14, but it show me a 3.1399968427..........in the screen, what's wrong ?

    Note: my soft is BCB.
    Never end on learning~

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    There are a number of situations where floats arent accurate, but I don't recall ever seeing one EXTEND output, usually it gets truncated.

    The cause is that a float uses [implementation-defined] ones and zeros to represent the mantissa (decimal part) and occasionally certain decimal values cannot be represented using that number of bits. Binary numbers are good for integers, but when you get into part of numbers, errors happen. Using doubles or long doubles can stave this off, but for any number of mantissa bits, there are still decimal numbers that cannot be represented.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21