Wednesday, March 28, 2012

how to assigned float number to DB ?

how can i assigned a float number with only one digit after the dot to the DB ?
i mean that i want to write this number 0.1 and not this 0.100000000 (that
what the sql does for me now..)
im using a storage procedure for this purpuse, so maybe the problem is there..
thanks !!
Hello,
Use Numeric instead of FLOAT datatype.
Thanks
Hari
"guy" <guy@.discussions.microsoft.com> wrote in message
news:04D80E57-189C-4C31-8729-1511B073B490@.microsoft.com...
> how can i assigned a float number with only one digit after the dot to the
> DB ?
> i mean that i want to write this number 0.1 and not this 0.100000000 (that
> what the sql does for me now..)
> im using a storage procedure for this purpuse, so maybe the problem is
> there..
> thanks !!
>
|||but if its Numeric it cant save me the 0.1 ... (or maybe i dont know how to
do this..) it save it like it was zero..
"Hari Prasad" wrote:

> Hello,
> Use Numeric instead of FLOAT datatype.
> Thanks
> Hari
> "guy" <guy@.discussions.microsoft.com> wrote in message
> news:04D80E57-189C-4C31-8729-1511B073B490@.microsoft.com...
>
>
|||Hello,
Use the below sample:-
declare @.t numeric(2,1)
set @.t = 0.1
select @.t
Thanks
Hari
"guy" <guy@.discussions.microsoft.com> wrote in message
news:590D1DF2-C360-45BB-9675-52533F59AABC@.microsoft.com...[vbcol=seagreen]
> but if its Numeric it cant save me the 0.1 ... (or maybe i dont know how
> to
> do this..) it save it like it was zero..
> "Hari Prasad" wrote:
|||On Sat, 23 Jun 2007 01:38:00 -0700, guy wrote:

>how can i assigned a float number with only one digit after the dot to the DB ?
>i mean that i want to write this number 0.1 and not this 0.100000000 (that
>what the sql does for me now..)
>im using a storage procedure for this purpuse, so maybe the problem is there..
>thanks !!
Hi Guy,
The only difference between 0.1 and 0.100000 is representation; their
values are exactyl equal. Since the internal representation for numeric
datatypes is different from what you see anyway, this question really
can't be answered. Whether you assign 0.1, 0.10000 or 0.2/2 to a float
variable or column, the result will always be the same.
So, if you want to STORE numbers with only one decimal place, then
Hari's answer is correct - you can't do that with float numbers, but you
can with the datatype numeric. If, on the other hand, you want to store
float numbers but REPRESENT them with one digit after the decimal place,
check out the subjects STR and CONVERT in Books Online. Note that these
functions convert a float value to a string representation, so the value
is no longer considered a number after this conversion!
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

No comments:

Post a Comment