473,809 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server 2K problem with fractional real values

I have a field of type Real in my SQL 2K database. I stored a value of
..35 in the field.

When I "Open Table"->"Return All Rows" in the Enterprise Manager I get
back .35 for the field value.

I went to The SQL Query Analyzer and executed the following T-SQL:

SELECT field
FROM table

I got back 0.34999999 for the field.

When running stored procs against the field I also get back 0.34999999.
This is causing problems in my app. I can use the Round T-SQL
statement to get back the value I expect, but this causes app
development problems. For a goof I put 1.35 in the field and T-SQL did
return 1.35. This problem only seems to occur with 0.nnn values. I
also tried a float data type for the field but I had the same problems
I had with real.

Why is T-SQL returning 0.34999999 for my field?

Jul 23 '05 #1
1 1714
On 9 Mar 2005 13:24:08 -0800, co***********@h otmail.com wrote:
I have a field of type Real in my SQL 2K database. I stored a value of
.35 in the field. (snip)Why is T-SQL returning 0.34999999 for my field?


Hi computer_prog,

The datatypes real and float are for approximate numbers. The internal
representation precludes exact representation of many fractions. Just as
the value 1/3 can never be represented exactly as a fraction in our
decimal system, the value 35/100 can't be represented exactly in a float
or real datatype (but 25/100 can, incidentally).

If you need exact numeric precision, don't use float or real. Use
decimal or numeric instead.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2278
by: Christian Wetzig | last post by:
hi, i have a table with test_field of type "TEXT". when i do: select test_field from test where id=1; the connection (with psql) hangs and no output is received, so i have to kill psql. this occurs, at first sight, if length(test_field)>32748.
5
24242
by: Michael Søndergaard | last post by:
I Pascal there are a function for retriving the fractional part of a real number (Frac), I can't find any in the dotnet framework. The function needs to remove the integer part and keep only the decimal part. Any hints... I am hoping that I don't need to create a new class and method for that function /Michael Søndergaard
7
2683
by: Oenone | last post by:
Can anyone explain why the following happens? \\\ Dim d1 As Decimal = CDec("100") Dim d2 As Decimal = CDec("100.00") MsgBox(d1.ToString) 'displays "100" MsgBox(d2.ToString) 'displays "100.00" MsgBox(d1 = d2) 'displays "True"
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.
2
4032
by: djzbor | last post by:
Any who can help!! let i have a number 16.0230045 i want to count the fractional part of this number means i want to get the number of digits of the fractional part of this number and store each digit in an array as well. i.e i have a;//where size is the number of digits of the fractional parts of my number how can i do that using C++. finally i should have my array to hold all the digits. Remember my number can be type float ,or double.
6
2925
by: Alexander Stoyakin | last post by:
Hello, please advise on the following issue. I need to check that difference between two double values is not higher than defined limit. int main() { double limit = 0.3; double val1 = 0.5, val2 = 0.2; if ( (val1 - val2) limit )
10
9853
by: schaefer.mp | last post by:
Does anyone know of an approximation to raising a negative base to a fractional exponent? For example, (-3)^-4.11111 since this cannot be computed without using imaginary numbers. Any help is appreciated.
89
5784
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
18
1438
by: Philluminati | last post by:
I am writing a poker game which needs to work with cash. I am aware that there are problems with floats that make them unsuitable for storing money values. On top of this I may be expected to do operations such as £10.52 / 3. Which data type should I use instead? Is there an Industry standard one? Further to this, is anyone away of legally what the obligations would be when the outcome is 3.566666667? does the customer get 56 or 57p?...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.