Problems With Float Numbers

May 28, 2007

hi

im using a stored procedure to insert float numbers in a data base....the parameter i send to the stored procedure is a float but every time i use it, it inserts a number with a lot of extra numbers i mean if i try to insert 5.3 it inserts 5.30000019073486 any idea why this is happening???

thak you

View 6 Replies


ADVERTISEMENT

Float Numbers

Apr 3, 2006

Hi!How do I do to make t-sql not rounding the result that i returned?For example:0.9616458*60 = 57,698748 (in any calculator)while following:--------------------------------declare @a floatdeclare @b intset @a=0.9616458set @b=60print @a*@b---------------------------------will show :57.6987How do I do to make MSSQL to show me the value whothout rounding it?Thanks!

View 16 Replies View Related

Convert A Binary Float To FLOAT Datatype

Apr 9, 2007

I can't take full credit for this. I want to share this with Jeff Moden who did the important research for this calculation here.

All I did was just adapting some old code according to the mantissa finding Jeff made and optimized it a little


Some test codeDECLARE@SomeNumber FLOAT,
@BinFloat BINARY(8)

SELECT@SomeNumber = -185.6125,
@BinFloat = CAST(@SomeNumber AS BINARY(8))

SELECT@SomeNumber AS [Original],
CAST(@SomeNumber AS BINARY(8)) AS [Binary],
dbo.fnBinaryFloat2Float(CAST(@SomeNumber AS BINARY(8))) AS [Converted],
@SomeNumber - dbo.fnBinaryFloat2Float(CAST(@SomeNumber AS BINARY(8))) AS [Error]

And here is the code for the function.CREATE FUNCTION dbo.fnBinaryFloat2Float
(
@BinaryFloat BINARY(8)
)
RETURNS FLOAT
AS
BEGIN
DECLARE@Part TINYINT,
@PartValue TINYINT,
@Mask TINYINT,
@Mantissa FLOAT,
@Exponent SMALLINT,
@Bit TINYINT,
@Ln2 FLOAT,
@BigValue BIGINT

SELECT@Part = 1,
@Mantissa = 1,
@Bit = 1,
@Ln2 = LOG(2),
@BigValue = CAST(@BinaryFloat AS BIGINT),
@Exponent = (@BigValue & 0x7ff0000000000000) / EXP(52 * @Ln2)

WHILE @Part <= 8
BEGIN
SELECT@Part = @Part + 1,
@PartValue = CAST(SUBSTRING(@BinaryFloat, @Part, 1) AS TINYINT),
@Mask =CASE WHEN @Part = 2 THEN 8 ELSE 128 END

WHILE @Mask > 0
BEGIN
IF @PartValue & @Mask > 0
SET @Mantissa = @Mantissa + EXP(-@Bit * @Ln2)

SELECT@Bit = @Bit + 1,
@Mask = @Mask / 2
END
END

RETURNSIGN(@BigValue) * @Mantissa * POWER(CAST(2 AS FLOAT), @Exponent - 1023)
END
Thanks again Jeff!


Peter Larsson
Helsingborg, Sweden

View 3 Replies View Related

Formatting Numbers In A Mixed Column (numbers In Some Cells Strings In Other Cells) In Excel As Numbers

Feb 1, 2007

I have a report with a column which contains either a string such as "N/A" or a number such as 12. A user exports the report to Excel. In Excel the numbers are formatted as text.

I already tried to set the value as CDbl which returns error for the cells containing a string.

The requirement is to export the column to Excel with the numbers formatted as numbers and the strings such as "N/A' in the same column as string.

Any suggestions?



View 1 Replies View Related

Query Analyzer Shows Negative Numbers As Positive Numbers

Jul 20, 2005

Why does M$ Query Analyzer display all numbers as positive, no matterwhether they are truly positive or negative ?I am having to cast each column to varchar to find out if there areany negative numbers being hidden from me :(I tried checking Tools/Options/Connections/Use Regional Settings bothon and off, stopping and restarting M$ Query Analyer in betwixt, butno improvement.Am I missing some other option somewhere ?

View 7 Replies View Related

I Need To Update A Table With Random Numbers Or Sequential Numbers

Mar 11, 2008



I have a table with a column ID of ContentID. The ID in that column is all NULLs. I need a way to change those nulls to a number. It does not matter what type of number it is as long as they are different. Can someone point me somewhere with a piece of T-SQL that I could use to do that. There are over 24000 rows so cursor change will not be very efficient.

Thanks for any help

View 6 Replies View Related

Generate List Of All Numbers (numbers Not In Use)

Feb 21, 2007

I have an 'ID' column. I'm up to about ID number 40000, but not all are in use, so ID 4354 might not be in any row. I want a list of all numbers which aren't in use. I want to write something like this:

select [numbers from 0 to 40000] where <number> not in (select distinct id from mytable)


but don't know how. Any clues?

View 1 Replies View Related

Dataflow To Excel - Convert Numbers Stored As Text To Numbers Excel Cell Error

Mar 27, 2007

I'm trying to write data to excel from an ssis component to a excel destination.

Even thought I'm writing numerics, every cell gets this error with a green tag:

Convert numbers stored as text to numbers

Excel Cells were all pre-formated to accounting 2 decimal, and if i manually type the exact data Im sending it formats just fine.

I'm hearing this a common problem -

On another project I was able to find a workaround for the web based version of excel, by writing this to the top of the file:

<style>.text { mso-number-format:@; } </style>

is there anything I can pre-set in excel (cells are already formated) or write to my file so that numerics are seen as numerics and not text.

Maybe some setting in my write drivers - using sql servers excel destination.


So close.. Thanks for any help or information.

View 1 Replies View Related

Float Or Int

Feb 18, 2004

Does it make a difference if I use the Float or Int data type for a field such as ReceiptNumber or CheckNumber?

Thanks for any thoughts,

View 5 Replies View Related

How To Set Float Precision

Feb 20, 2000

Hi!
I'm quite new to SQL Server. I need to set a float datatype to display something like 3.55. However, all values that are stored in the float column are truncated to 4 or some other single digit. How can this be prevented?

Regards,
Sam

View 1 Replies View Related

Float Precision

Sep 5, 2002

Hello everyone,

I am sure this is a newbie question as I am new to Microsoft SQL server but any help is greatly appreciated. I am populating a SQL database from an AS400. The decimal numbers from the AS400 are coming accross with extra decimals. (ie. 63.02 is coming accross as 63.0200001)

Is there a way to limit the number of decimals in a float or real field - or a SQL command I can put in a script to truncate each field to 2 decimal places after they are populated.

Thanks,
Randy

View 1 Replies View Related

Float Vs. Decimal

Jun 29, 1998

We are having problems with rounding errors on large monetary calculations in sql server 6.5

The calculations include float fields (for volumes and unit of measure conversions in product movements). I was wondering if the float being "approximate" could be the problem.

IF it is, why would I want to store things as a float instead of a dec(28,14)?
Is it faster to compute numbers stored as approximate binaries? Will we see a big performance hit if we switch some of the table`s field`s to decimals?

Thanks in advance.

View 3 Replies View Related

Convert Int To Float

Jun 21, 2007

Hi,

why does converting integer to float take so long? Its a column with about 5 Million rows.
I want to avoid cast(inumber1 as float) / cast(inmuber2 as float), thats why converting them. Queries should be a bit faster after that.. hope so :)
Thanks a lot

View 14 Replies View Related

Can Anyone Help With With Datatype Float

Aug 30, 2007

I have some engineering data in my table and the db designer is representing it with a float datatype. Here's what is happening. If I query on a record based on id num and get a row and put it in text boxes in my Windows App, min_riv_hd_dia (the float) is 0.026<14 zeroes>2. If I try to query and get that same record again but this time based on id num and min_riv_hd_dia equal to 0.026<14 zeroes>2, I get no row found. If I just do a select on this row based on id number, sql server displays it as 0.026. But if I query with 0.026 as my value, still the row is not found. If I query min_riv_hd_dia > 0.026, the record is found.

So my question is, how can I tell the exact value that must be input in my search criteria in order to find this row?

Thank you so much if you can help!

View 4 Replies View Related

Float In VB-Skript

Dec 29, 2003

Hi there
I have two Databases
in both databases are fields with float - no null
If I am transfering data from one database to the other everything works well unless there is a comma in the field ( 0,99 or 123,456 )

"SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti kelbezeichnung,Artikeltext1,EDVEingang ,EDVAusgang,InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & EDVEingang & "," & EDVAusgang & "," & ArtMenge & ")"
"
where EDVEingang and EDVAusgang are defined as float, no null

Then the programm stops with the following message:
Within the INSERT-Procedure there are less columns then there are Contents in the Value-Clause.

I have to finish the programm until tomorrow morning and don't know what the problem is.

If anybody has an idea, please let me know.

regards
Reiner

View 14 Replies View Related

Float Or Decimal?

May 4, 2004

When should I choose decimal over float and vice versa?

Mike B

View 4 Replies View Related

Float Problem

Apr 10, 2008

Hi Everyone,

here is a simple SP

Create procedure test
@input float
as
Begin
return @input
ENd

If I execute the following
declare @output float
exec @output=test 1.12121
select @output

why I got 1 not 1.12121?

any idea? How to get the correct result?

Thank you in advance

View 2 Replies View Related

Float Vs Decimal

Nov 22, 2006

select convert(float,'1.2334e+006')1233400.0select convert(decimal(20,2),'1.2334e+006')Server: Msg 8114, Level 16, State 5, Line 1Error converting data type varchar to numeric.Is there any way around?Is there any set options? I tried arithabort or arithignore and theydon't work.Thanks.

View 2 Replies View Related

RESULT IN FLOAT

Jul 20, 2005

HI,I WANT THIS TO PRODUCE EXACT RESULT. (IN SQL SERVER)SELECT (23 / 233) * 100THE ANSWER SHOULD COME 9.871244635 OR 9.87BUT IT RETURNS 0.I WANT THE PERCENTAGE.HOW TO HANDLE THIS KIND OF PROBLEM.IS THERE ANY SET COMMAND FOR IT?THANKST.S.NEGIJoin Bytes!

View 1 Replies View Related

Pricision Of Float

Jul 20, 2005

Hi,Just wonder whyPRINT CAST(0.0573542567654 AS float)will give the rounded reult0.0573543rather than the original number?"float" should be 'big' enough to hold numbers that have even moredecimal places. How come it round up at the 7 decimal place?since I need to do some calculations with accumulated values. Therounded figure will cause significant error after a number of opertions.Are there any way to work around it?thanks*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 2 Replies View Related

Float Coumn Having Value -1.#IND

Mar 20, 2008



I had database with "-1.#IND" (Indefinite /infinite) values in float columns.



Is there anyway I can insert -1#IND value into float column using some insert query and query analyzer? I am using SQL Server 2000.



I want to insert this value to replicate the issue..just for testing. I am also wondring how my database got these values.



Thanks in Advance!

View 1 Replies View Related

Float And Numeric

Nov 20, 2007

I am keep getting an arithmetic overflow converting float to type numeric when running a script that looks something like this.

insert into table1
(
column1
)
select
column2
from source server.

column1 is a numeric (28,8) and column2 is float.
there are about 2000000 records in column2, and I know that when I tried just copying the top 1000000 wasn't a problem.

does anyone know what could be causing this problem???

*it's not because the data in column2 is out of range.

thank you

View 10 Replies View Related

Float Column Having -1#IND Value

Mar 20, 2008

I had database with "-1.#IND" (Indefinite /infinite) values in float columns.



Is there anyway I can insert -1#IND value into float column using some insert query and query analyzer? I am using SQL Server 2000.



I want to insert this value to replicate the issue..just for testing.I am wondring how my database got these values.



Thanks in Advance!

View 1 Replies View Related

Converting SQLMoney To C# Float ?

Dec 23, 2006

I'm using c# 2.0.
I have a datareader that reads an invoice line item from a table in my SQL Server database. The UnitPrice field is a Money field in SQL server. At the same time I have an invoice class in my application that has a UnitPrice property which is a float.
How do I convert the SQLMoney to a float using my datareader?
Right now I have:
cm.CommandText = "SELECT ItemID, Quantity, UnitPrice, Discount FROM tblInvoiceLineItems";
using (SqlDataReader dr = cm.ExecuteReader())
{
while (dr.Read())
{
LineItem li = new LineItem();
li.UnitPrice = (float)(double)dr.GetFloat(3);  // cast error here.
lineItems.Add(li);
}
}

View 1 Replies View Related

Diff Between Float And Real

Jan 7, 2008

Hi All,
What is the difference betwen real and float datatype of SQL  server.
Please one exapmle for each.
The  real datatype is like a float except  that real can only store numbers.What does it mean: float can store even characters.
Thanks
Abdul
 
 
 

View 2 Replies View Related

Does SQL Substitute Float = 0 With DBNull.Value?

Mar 11, 2004

Hi
I have only been coding in .Net for about six months, and am not sure if this is a C# problem or an SQL one. I use the Data Access Application Block in my program.

I have two optional fields on my form (RangeFrom and RangeTo). If the user chooses not to enter data into these textboxes(textbox = ""), an entry on the db is created with null values. It works.

But sometimes the user wants to enter 0 as either an upper or lower end of a range. This is where my problem comes in. My program saves 0 as null too.

In my program I do a test on the textboxes and populate two float values in a business object (objQuestion) accordingly, like this:


if (txtrangefrom.Text != "") {
objQuestion.RangeFrom=float.Parse(txtrangefrom.Text);
objQuestion.RangeTo=float.Parse(txtrangeto.Text);
}
else {
objQuestion.RangeFrom=Convert.ToSingle(null);
objQuestion.RangeTo=Convert.ToSingle(null);
}


And this is what my Business object look like. It sets up the parameters and calls the Data Access Application Block to create an entry in my table:


// fieldslist
float cvintRangeFrom;
float cvintRangeTo;

//properties
public float RangeFrom {
get {
return cvintRangeFrom;
}
set {
cvintRangeFrom = value;
}
}

public float RangeTo {
get {
return cvintRangeTo;
}
set {
cvintRangeTo = value;
}
}

// some code deleted for readability....

public int AddOption() {
string cvstrSpName = "addOption";
SqlParameter [] cvstrStoredParams = SqlHelperParameterCache.GetSpParameterSet(gcstrConnectionString, cvstrSpName, true);
//lines deleted for readability...
//check if the optional fields have a value associated with them. if not, assign dbnull.value.
cvstrStoredParams[4].Value=(cvintRangeFrom != Convert.ToSingle(null) ? cvintRangeFrom : (object)DBNull.Value);
cvstrStoredParams[5].Value=(cvintRangeTo != Convert.ToSingle(null) ? cvintRangeTo : (object)DBNull.Value);
//lines deleted for readability...
SqlHelper.ExecuteNonQuery(gcstrConnectionString, CommandType.StoredProcedure, cvstrSpName, cvstrStoredParams);
return(cvintOptionID = Convert.ToInt32(cvstrStoredParams[0].Value));
}


I use Convert.ToSingle when working with nulls (or possible nulls) because I get an error when I use float.parse for this.

The thing is, after this method AddOption has been executed, I test the value if the business object's rangefrom (that is where I entered 0) and display it on my form. I still shows a 0, but on my database table it is null!


objQuestion.AddOption();
//txtrangefrom.Text=""; on the next line I test the value in the business object...
txtrangefrom.Text=objQuestion.RangeFrom.ToString(); // and this displays 0!!!
//txtrangeto.Text="";
txtrangeto.Text=objQuestion.RangeTo.ToString();


So to me it seems the problem seems to be either the DAAB or on the SQL side, but hopefully somebody can prove me wrong! I was thinking that it could also be float.parse/Convert.ToSingle methods and have done various tests, but I am none the wiser...
Any help or ideas will be greatly appreciated...

View 2 Replies View Related

Float Data Type

Oct 17, 2001

I am using SQL Server 7.0. I create a table with one field..type of float.
Using SQL Server Query Analyzer:
INSERT INTO MyTable(MyField) VALUES (4.9)
INSERT INTO MyTable(MyField) VALUES (Round(4.9,2))


SELECT * FROM MyTable

Result = 4.9000000000000004

This is a basic example of a problem I am having in another table with the
same float field that I am using to store money in. I don't want to use
the money field as the BDE from Borland has some issues with money fields.
Any suggestions? Thanks in advance.

View 1 Replies View Related

How To Format Float Datatype?

Apr 5, 2000

For example, I have a float datatype field with a value of .2501
I select using ROUND(Field,3) and get .25 as a result, but what I need to display is .250 (three decimal places.) How can this be done?
Thanks,
Paul

View 3 Replies View Related

Float Data Type

Oct 27, 2000

We are using a GL package called Solomon. It uses SQL Server 7.0 for it's database. I want to create a data warehouse using this data as the source. The package uses the float data type for dollar amounts. The dollar amounts in the data have either no numbers, 1 number, or 2 numbers after the decimal point. Is the float data type the best one to use in my data warehouse for dollars and cents, or should I try using the monetary or decimal (precision 2) data type? Which type uses the most storage?

View 2 Replies View Related

Float Data Types

Mar 2, 2005

I've got a float data type in a table. I imported data from a csv file. One value was 0.5195, but when I use the value in a calculation or select it using the Query Analyser, I'm getting a value of 0.51949999999999996. Is there any way around this, it's a real pain?

Thanks in advance.

View 1 Replies View Related

Money And Float Conversion

Aug 22, 2005

hi,

i'm get some strange behaviour with the money and float type. with a calculator divide 70 by 47 and multiply by 40 (70 / 47 * 40) and you get 59.5744 (rounded to nearest 4 decimal places). now try this in query analyser with the 70 as a money type and the result as a float:

declare @price money
declare @result float
select @price = 70
select @result = @price / 47 * 40
Print 'result = ' + str(@result,18,4)

now this will print out 59.5720

am i missing something ?

View 2 Replies View Related

Float Value Doesn&#39;t Come Up Properly...

Jun 19, 2001

I define one of my columns as FLOAT. Some of the values are negative and positive with precision 8 or 12. When I run updates against that column and then check the data all values are 0.

Any idea why?? I appreciate it.

Thanks,


David

View 1 Replies View Related

Float To Datetime Conversion

Aug 3, 2007

I need to convert values in a float data type field to that of datetime. The float data type field currently contains values such as 20060927,20060928, etc. Any suggestions?

Thanks in advance,
sajmera

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved