Re: Float value changes unexpectedly when performing math on field

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



AkAlan,

Float fields, by definition, have some built-in imprecision. This is a side effect being able to store very large numbers in smaller spaces. Even though you might expect that imprecision on very large numbers, it happens on small numbers as well. (It is all part of the representation of numbers.)

So, ideally, if that is not what you want, you should NUMERIC or DECIMAL, but not float. (Although, I am getting 100.9 from a float when I enter 100.9.)

Having said that though, you can get the display that you want by:

SELECT FloatColumn AS A, ROUND(FloatColumn) AS B
FROM table

Should give you:

A B
-------------- ---------------
100.8999999 100.9

Hope that it helps.
RLF

"AkAlan" <AkAlan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:B4B97F70-F19F-4C1B-9B3D-60ABEC65B949@xxxxxxxxxxxxxxxx
I have a Float field that stores a meter reading. The actual meter can
rollover to zero so I have a rollover count and rollover point so I can
display the reading as the user sees it, but still store the total number of
hours the equipment has operated. The problem I'm having on one meter reading
is, the user inputs 100.9, the table stores 100.9 but the sp displays
100.8999999. Here is the select statement I have in the sp:
CASE WHEN [RolloverCount] > 0 THEN [MeterReading] - ([RolloverPoint] *
[RolloverCount]) ELSE [MeterReading] END

What can I do differently so the correct value is returned?



.



Relevant Pages

  • Re: Rounnding Issue
    ... In the database, if the datatype is a float, it will not contain EXACTLY 20.45 because that value CANNOT be stored in a float. ... A float is a binary fraction and asking a binary fraction to store 20.45 is like asking a decimal fraction to store 1/3. ...
    (microsoft.public.sqlserver.programming)
  • Re: Extremely wierd problem I just cannot explain...works in debug, does not work in release.
    ... a float or double should be used to store _only_ measured ... kimi no koto omoidasu hi nante nai no wa ... kimi no koto wasureta toki ga nai kara ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: storing floating point data with using float or double
    ... I don't intend to store all of the 100,000 datapoints, but rather a subset ... I don't need the precision of a float, the above values would be fine to ... A couple of ideas I have come up with is to try compressing the array of ... though about breaking the values into an sbyte and a byte like this: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: storing floating point data with using float or double
    ... You can store the values as fixed point values in shorts. ... You would be able to get a precision of three decimals if you'd like. ... The numbers you could store this way would range from -32.768 to 32.767. ... Recently it was requested that I add the ability to generate graphs from the raw, un formatted test results (100,000+ float values) ...
    (microsoft.public.dotnet.languages.csharp)