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
ADVERTISEMENT
Oct 6, 2015
I have a column type of float and How to convert it show like this
default value =39260.80 MY db use this ',' seperator instead of '.'
wanna convert 39,260
This code is working if using '.' seperator
SELECTÂ parsename(convert(varchar,CAST(floor('39260.80') AS MONEY),1),2)
not work using ',' seperator
SELECTÂ parsename(convert(varchar,CAST(floor('39260,80') AS MONEY),1),2)
View 12 Replies
View Related
Mar 24, 2008
How do I format the money or float field types to 2 decimal places during a SELECT statement?
View 4 Replies
View Related
Jan 16, 2013
What is the difference between Money and (Float or Decimal) Datatype. If we use Float or Decimal instead of Money, will we loose any functions..?
View 4 Replies
View Related
Apr 2, 2006
Hi!
When I write:
'SELECT Amount FROM tTransaktion'
I get returnvalues such as '12000.0000'. Instead, I want it to return '12 000'.
The Amount column is of datatype money. Is this possible!?
Thanks!
View 7 Replies
View Related
Jan 25, 2005
have a SQL server table with a vairbale unitCost of type money and via a stored procedure I am trying to update it. Through asp I capture the value as a string and then ATTEMPT to convert it into a variable of type money before executing the stored procedure as follows.
SqlParameter parameterUnitCost= new SqlParameter("@unitCost", SqlDbType.Money,8);
parameterUnitCost.Value = unitCost;
myCommand.Parameters.Add(parameterUnitCost);
This gives me an input string error. On the other hand if I change that line to the following, the page works flawlessley:
SqlParameter parameterUnitCost= new SqlParameter("@unitCost", SqlDbType.Money,8);
parameterUnitCost.Value = 25.45;
myCommand.Parameters.Add(parameterUnitCost);
any thoughts???
View 3 Replies
View Related
Jun 21, 2006
Hi...
I've this type of data: 148.667,31 or 344.207.6 ... type text.
I need to convert it to money in a query...
How I can do this?
Thanks...
Paolo Manfrin
View 6 Replies
View Related
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
Aug 30, 2013
I have a field 1700 its a float. I need that converted to time.
View 2 Replies
View Related
Mar 28, 2008
Happy Friday!
A while since I have posted a question, and this one is probably real easy.
I am trying to store numeric values from a php form in MSSQL 2000 database. However, the columns are set to float and if the value is 1.00, when entered into the table it is saved as 1
If I change the column type to money, the query fails, with an error message of conversion of datatype varchar to datatype money statement terminated.
anybody know what I need to do? do I need to do something in my query to specify that this is NOT varchar data?
View 2 Replies
View Related
Apr 26, 2007
I am running into some issues with conversion and would appreciate someone who can help on this.
I need to roll up a column which contains numeric (float) data but it is stored in a varchar field.
I was trying to do the following (please note that Activity field is varchar(50) in MyTable):
SELECT CONVERT(float, (NULLIF(Activity,0))) from MyTable
and i get the following error.
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value '-39862.8' to data type int.
I even tried with case statement (as below) but still got same issue.
SELECT CASE ISNUMERIC(NULLIF(Activity,0))
WHEN 1 THEN
CONVERT(float, (NULLIF(Activity,0)))
ELSE 0
END
from MyTable
Thanks,
Ashish
View 7 Replies
View Related
Oct 16, 2007
I have a special need in a view for a money column to look like money and still be a money datatype. So I need it to look like $100.00 (prefered) or 100.00(can make work).
If I convert like this '$' + CONVERT (NVARCHAR(12), dbo.tblpayments.Amount, 1) it is now a nvarchar and will not work for me.
How can I cast so it is still money? by default the entries look like 100.0000.
They must remain a money datatype.
View 9 Replies
View Related
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
May 6, 2007
Hi,I'm having some trouble with my asp.net page and my sql database. What I'm trying to do is allow the user to upload an number to the database, the number is a money amount like 2.00 (£2.00) or 20.00(£20.00). I've tried using money and smallmoney datatypes but the numbers usually end up looking like this in the database...I enter 2.00 and in the database it looks like 2.00000, and even if I enter the information directly into the database I get the same results. I'm not going to be using big numbers with lots of decimal places like this 1000,000,0000. Can anyone help me? All I want is to know what to set the value to on my aspx page and what setting to set the field to in my database, I'd just like two pound to appear as 2.00. any help would be great.
I'm using Microsoft Visual Web Developer 2005 Express Edition and Microsoft SQL Server 2005 if that helps.
Thanks.
View 2 Replies
View Related
Dec 28, 2006
Please i need to display the money column in DataBase in an asp.net page but i get something like this 786.0000 how can i format it so that i get something like 786.00
Thanx
View 3 Replies
View Related
Jan 13, 2007
Hi everybody.Here's my Product tableID int,Title nvarchar(50),Price moneyHow can I get value from price field like thisIF PRICE is 12,000.00 it will display 12,000IF PRICE is 12,234.34 it will display 12,234.34Thanks very much...I am a beginner. Sorry for foolish question
View 7 Replies
View Related
May 19, 2007
Argggg....Please help.I need to store money in SQL Server.I am using C# and a stored procedure to insert.How do you accomplish this? Specifically what datatype should the money variable be in C# during the insert? It's initial value is a string as it is entered from a text field.I have been trying for over an hour now to simply insert money into SQL Server using C# and have it stored as a money type!Thanks
View 3 Replies
View Related
Oct 10, 2007
hello everyone...,i have problem in money format...i have moneytable is containning: userid money A 20000,0000 B 40000,0000userid type varchar(50)money type money i have store procedure like this:ALTER PROCEDURE [dbo].[paid]( @userid AS varchar(50), @cost AS money, @message as int="1" output)ASbegin transactiondeclare @money as money select @money = moneyfrom moneytablewhere userid=@useridif (@money > @cost)beginset @money = @money - @costUPDATE moneytable SET money = @money WHERE userid=@useridset @message ='1'endelsebeginset @message = '2' endCOMMIT TRANSACTION when i execute this procedure. i insert value to userid Acost 100,0000 it can not decrease, because cost 100,0000 is same with 1000000, why is like that?i want cost 100,0000 is same with 100. how can i do that? thx...
View 6 Replies
View Related
Aug 29, 2004
Hi,
I have a field in database money. When I enter value for it the amount entered is for example 20.000. How can I compare this value with noraml vaules i.e. like 20 in my search engine. Will I need to convert it to varchar and then compare it or is there some other way. Also if I need to convert it to varchar, how can I do it?
Thanks in advance,
Uday
View 6 Replies
View Related
Apr 24, 2005
Hi All,
Here in Belgium, we work with a comma as decimal seperator, also in all the web apps...
I've tried to update a money table on the sql with following statement
update parts set article = '" & art & "' and price= cast(" & p & " as decimal(5,2)) where supid=202
in this example p is a variable and contains figures like 5,7
This statement always give following error Incorrect syntax near the keyword 'as'
does some have an idea how to fix this one ?
thx
View 4 Replies
View Related
Apr 5, 2001
Is there a way to format the output of an calculation so that a comma is used as decimal symbaol and a periode after each 3 digits left of the comma ?
We're calculating salary increase like 5000 * 1.025 and the output should look like 5.250,00
Thanks for any help
Charles
View 2 Replies
View Related
Jan 27, 2003
Greetings,
How do you keep or round a money datatype to use only 2 decimal places? I have an instance where I am multiplying a money with a decimal datatype. The decimal has up to 8 decimal places. This is causing the money datattype to extend to 4 decimal places. This makes for problems when I am comparing 2 values.
ex.)
IF 14.88 >= 14.8821
99% of the time this does not happen, but is causing problems. Does anyone have any suggestions?
thanks in advance,
Roger
View 2 Replies
View Related
May 8, 2004
From query analyzer how can I change the field datatype from money to varchar?
Alter table tablenaame alter column columnname varchar(30)--Is not working.
View 2 Replies
View Related
May 11, 2004
How can I alter a field datatype from money to varchar?
View 2 Replies
View Related
Jun 3, 2008
Hi, I have data in a Payment field:
45.14 - was orig in text format.
Now after converting to money, I see it as this:
45.1400
I need to get rid of the zeros! Anyone please help?
Thanks!
View 3 Replies
View Related
Jan 12, 2007
Hi everybody.
Here's my Product fields
ID int,
Title nvarchar(50),
Price money
How can I get value from price field like this
IF PRICE is 12,000.00 it will display 12,000
IF PRICE is 12,234.34 it will display 12,234.34
Thanks very much...I am a beginner. Sorry for foolish question
View 4 Replies
View Related
Mar 25, 2007
Hi all. Is there a way in SQL to convert the integer to currency format? just for example....
4000 convert to 4,000
1312500 convert to 1,312,500
30000 convert to 30,000
Most of you will say "Do it in your front end"... but the problem is I don't know how to do it in my Report(Business Intelligence Project). If anyone of you knows, tell me please... Thanks. :)
-Ron-
View 12 Replies
View Related
Feb 12, 2008
Do you usually use the money or smallmoney datatype for US dollars in a table, or do you use a decimal datatype, and if so which. Any opinions on the advantages and disadvantages of each?
If you use money or smallmoney, do you usually add a constraint to make sure the value is even to the penny (no $24.3487 type amounts)?
CODO ERGO SUM
View 1 Replies
View Related
Mar 3, 2008
I'm looking for a way to "secure" a column of MONEY values. The idea is to hide the value without resorting to actual SQL encryption services that would require converting the MONEY to a VARBINARY. In short, I want to keep the column type as MONEY, but I want to scramble the value, so its still a valid MONEY type.
The goal is to have a pair of UDF's SCRAMBLE() and UNSCRAMBLE() that work on MONEY.
I've done some searching, but have not found anything along this topic.
Does anyone have any ideas on how to do this?
View 6 Replies
View Related
May 30, 2007
I have a Windows 2003 server, with SQL 2005. How do i change the culture/regional options for the database as on my local test machine (which seems to be exactly the same in terms of windows regional settings and SQL server settings) the currenency fields show with a £ signs as expected, however on my production box they are $. I know this should be simple but its the night before a deadline and my brain is screwed. Please help!!
View 5 Replies
View Related
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
Oct 10, 2006
I use asp.net 2.0 and sql server 2005 for a web site (and Microsoft enterprise library).When I run aplication at local there is no problem but at the server I take this error:Disallowed implicit conversion from data type varchar to data type money, table 'dbname.dbo.shopProducts', column 'productPrice'. Use the CONVERT function to run this query.productPrice coloumn format is money. It was working correctly my old server but now it crashed.How can I solve this problem? And why it isn't work same configuration? My code:decimal productPrice;Database db = DatabaseFactory.CreateDatabase("connection");string sqlCommand = "update shopProducts set ......................,productPrice='" + productPrice.ToString().Replace(",", ".") + "',..................... where productID=" + productID + " ";db.ExecuteNonQuery(CommandType.Text, sqlCommand)
View 1 Replies
View Related
Jun 25, 2007
Hi there,I have a table products with product_price money(8) field. I have a stored procedure,CREATE procedure p_dat_update_product( @product_id int, @product_price decimal) asset nocount ondeclare @msg varchar(255) -- error message holder-- remove any leading/trailing spaces from parameters select @product_id = ltrim(rtrim(@product_id)) select @product_price = ltrim(rtrim(@product_price))-- turn [nullable] empty string parameters into NULLs if (@product_id = N'') select @product_id = null if (@product_price = N'') select @product_price = null-- start the validation if @product_id is null begin select @msg = 'The value for variable p_dat_update_product.@product_id cannot be null!' goto ErrHandler end-- execute the query if exists (select 'x' from product where product_id = @product_id) begin update dbo.product set product_price = @product_price where product_id = @product_id end if (@@ERROR <> 0) goto ErrhandlerreturnErrHandler: raiserror 30001 @msg returnGO And a class function public void Edit_Product(string product_id,string product_price) { decimal dec_product_price = decimal.Parse(product_price); SqlDataServ oMisDb = new SqlDataServ("LocalSuppliers"); oMisDb.AddParameter("@product_id", product_id); oMisDb.AddParameter("@product_price", dec_product_price.ToString()); oMisDb.ExecuteCmd("p_dat_update_product"); }But i keep getting this error,Error converting data type nvarchar to numericoMisDb.ExecuteCmd("p_dat_update_product"); I do not know what to do and solve this. Is there something that i have done wrong.thanks in advance. PS: still learning aspx and ms sql
View 12 Replies
View Related