By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,364 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,364 IT Pros & Developers. It's quick & easy.

which datatype takes actuall value

P: 81
Hi,
in my database i gave a datatype as float so i entered a value as 3.10 but it taking as 3.1 and also i entered as 3.999 but it will taking as 4 how its possible
which datatype store the actuall value
ex : if i entered as 3.999 means it will as 3.999 only again if i given as 3.10 means it will take as 3.10 only
May 21 '08 #1
Share this Question
Share on Google+
8 Replies


debasisdas
Expert 5K+
P: 8,127
please find all the details here.
May 21 '08 #2

OuTCasT
100+
P: 374
Hi,
in my database i gave a datatype as float so i entered a value as 3.10 but it taking as 3.1 and also i entered as 3.999 but it will taking as 4 how its possible
which datatype store the actuall value
ex : if i entered as 3.999 means it will as 3.999 only again if i given as 3.10 means it will take as 3.10 only

use the datatype REAL
May 21 '08 #3

Delerna
Expert 100+
P: 1,134
Actually, I am not really understanding your question because if you enter 3.10 then 3.1 IS the real value, try it on your calculator.
So, if you want a variable number of decimal places then float is the correct type.
If you enter 3.10 then the real value is 3.1 which is what float will store
If you enter 3.199900 then the real value is 3.1999 which is what float will store.

If you want to store the value exactly as it was entered then you will have to save it as a varchar.
so if you enter 3.1000000 then it will be saved as 3.1000000

All number types will remove the zeros on the end because they are unnecessary
May 21 '08 #4

P: 81
use the datatype REAL
hi,
i used that one but its not working
May 21 '08 #5

P: 81
Actually, I am not really understanding your question because if you enter 3.10 then 3.1 IS the real value, try it on your calculator.
So, if you want a variable number of decimal places then float is the correct type.
If you enter 3.10 then the real value is 3.1 which is what float will store
If you enter 3.199900 then the real value is 3.1999 which is what float will store.

If you want to store the value exactly as it was entered then you will have to save it as a varchar.
so if you enter 3.1000000 then it will be saved as 3.1000000

All number types will remove the zeros on the end because they are unnecessary
Hi,
if i take varchar means on searching its not getting all values
May 21 '08 #6

ck9663
Expert 2.5K+
P: 2,878
It means you have to convert the value you're searching.

If this is for display purposes on your front-end, handle in on your front-end.

-- CK
May 21 '08 #7

Delerna
Expert 100+
P: 1,134
Hi,
if i take varchar means on searching its not getting all values
Yes, that is correct it won't bring back all the values.

This is because the numbers 3.1 and 3.10 are exactly same number
but the strings 3.1 and 3.10 are very different.
As I said in my previous post, I really don't understand the question.
Why does it matter that if you enter 3.10 and 3.1 is saved. They are both the same number. You may have a valid reason, I don't know.

If you convert the varchar as ck suggests then the zero will be dropped again.
If you keep the varchar idea then 3.1 and 3.10 won't match in a search.

So at this point you are faced with a decision.
All number types will drop zeros from the end of the decimal part. There is nothing you can do about that.
So either
1) you use decimal type, perhaps decimal(18,4) which means 4 decimal places.
With that
an entry of 3.1 will appear in queries as 3.1000
an entry of 4.190 will appear in queries as 4.1900

or

2) You use some other number type such as float or real
which means an entry of 3.10 will appear in queries as 3.1
and an entry of 4.190 will appear in queries as 4.19
or

3) you use a varchar and come up with some tricky way to keep the number as string but still be able to search correctly.

Perhaps you can select the field in your queries twice. Once for displaying the number as entered and the second one you convert it back to a number for your query searching.
May 21 '08 #8

P: 81
Yes, that is correct it won't bring back all the values.

This is because the numbers 3.1 and 3.10 are exactly same number
but the strings 3.1 and 3.10 are very different.
As I said in my previous post, I really don't understand the question.
Why does it matter that if you enter 3.10 and 3.1 is saved. They are both the same number. You may have a valid reason, I don't know.

If you convert the varchar as ck suggests then the zero will be dropped again.
If you keep the varchar idea then 3.1 and 3.10 won't match in a search.

So at this point you are faced with a decision.
All number types will drop zeros from the end of the decimal part. There is nothing you can do about that.
So either
1) you use decimal type, perhaps decimal(18,4) which means 4 decimal places.
With that
an entry of 3.1 will appear in queries as 3.1000
an entry of 4.190 will appear in queries as 4.1900

or

2) You use some other number type such as float or real
which means an entry of 3.10 will appear in queries as 3.1
and an entry of 4.190 will appear in queries as 4.19
or

3) you use a varchar and come up with some tricky way to keep the number as string but still be able to search correctly.

Perhaps you can select the field in your queries twice. Once for displaying the number as entered and the second one you convert it back to a number for your query searching.
HI,
Thank U for u suggession!!
Now I Got!!
May 22 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.