I want to insert a datatype real in a table only in this format.
Ex: I want to insert 1.05, but when i make a select it showm me 0.47999998927116394
how do i do to apper the value that i insert?? withot the rest of the numbers?
URGENT!
I've already tried to use decimal but now when I insert 0.48 it show me the result 0. What do I have to do? the code is:
Create Table Moeda
(
Data Datetime,
Moeda varchar(10),
Factor decimal,
CONSTRAINT Data_Moeda PRIMARY KEY (Data, Moeda)
)
Drop Procedure InserirMoeda
Create Procedure InserirMoeda
(
@Data Datetime,
@Moeda varchar(10),
@Factor decimal
)
AS
You must declare the precision and scale of a decimal data type.
col1 decimal(10,2) --10 digits with 2 after the decimal
FYI: Float and Real are approximate numeric date types. They are stored in a binary representation and many decimal values cannot be represented precisely. That is why float doesn't show the precise number of digits you tried to store. Terry L. Broadbent FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
and if i want to put in one field the value 1.053 and in another 0.48 it does'nt work... i show me in one 1.05 and in the other .48 I have to do this work until 6.00 pm. URGENT! Really Tanks.
and if i want to put in one field the value 1.053 and in another 0.48 it does'nt work... i show me in one 1.05 and in the other .48 I have to do this work until 6.00 pm. URGENT! Really Tanks.
Not knowing how you are going to use this , amount of data involved, what your trying to achieve etc ,etc. It's a bit difficult to work out what you really need.
See my example below: Put together very quickly so not the the neatest of solutions but I think it will work.
If you declare a column as data type DECIMAL(10,3) you get 10 total digits with 7 before and 3 after the decimal. You are defining the way the value is stored. You can't trim zeros, leading or trailing when storing the data.
Enterprise Manager, Query Analyzer and other client tools determine how to display the values. Typically, leading zeros are dropped. Trailing zeros are not. You can format the data for display but must be careful about the conversions you do. If you convert a numeric value to character type data, you may not be able to perform calculations and sort orders will likely change.
If you must maintain the data exactly as formatted, then store it as character type data. Then if you need to do calculations, convert the character data to numeric. This is highly irregular and inefficient. However, if the overriding criteria is maintaining the format as input, I don't see that you have much choice. Terry L. Broadbent FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.