|
|
Help with float data type |
|
Author |
Message |
Masriaty
|
Posted: Wed Feb 22 15:40:59 CST 2006 |
Top |
SQL Server Developer >> Help with float data type
Hi,
I am developing a web based application that deals with financial info
(coldfusion and sql server 2000 on shared server). All the numbers that
carry this info are of float data type. I ran into a situation when this
gives all kind of problems.
For example, I calculate cost after very small update of a salary and cost
may not increase notisably on the interface because there is always a mask
rounding up to 2, 3 or 4 digits depending on a setting. But most of data
manipulations, like creattion of adjustments are done in stored procedures
and the difference in new cost may be so small that rounding up to 11 digits
will give me a difference not less. Which in turn is saved in db as a record
that displayed later on the interface with the value of $0 rounded to 3
digits.
So, I am just wondering, should I use ROUND() function in the stored procs
and queries on calculations with the argument set to 2, 3 or 4? Or it is not
safe with financial data?
Thanks,
Gene
SQL Server163
|
|
|
|
|
Aaron
|
Posted: Wed Feb 22 15:40:59 CST 2006 |
Top |
SQL Server Developer >> Help with float data type
I would use DECIMAL not FLOAT for financial data.
http://www.aspfaq.com/2477
> Hi,
>
> I am developing a web based application that deals with financial info
> (coldfusion and sql server 2000 on shared server). All the numbers that
> carry this info are of float data type. I ran into a situation when this
> gives all kind of problems.
>
> For example, I calculate cost after very small update of a salary and cost
> may not increase notisably on the interface because there is always a mask
> rounding up to 2, 3 or 4 digits depending on a setting. But most of data
> manipulations, like creattion of adjustments are done in stored procedures
> and the difference in new cost may be so small that rounding up to 11
> digits will give me a difference not less. Which in turn is saved in db as
> a record that displayed later on the interface with the value of $0
> rounded to 3 digits.
>
> So, I am just wondering, should I use ROUND() function in the stored procs
> and queries on calculations with the argument set to 2, 3 or 4? Or it is
> not safe with financial data?
>
> Thanks,
>
> Gene
>
|
|
|
|
|
News
|
Posted: Wed Feb 22 15:56:46 CST 2006 |
Top |
SQL Server Developer >> Help with float data type
Well, with decimal I still have to specify number of digits to round to,
otherwise in many case it will default to integer. I experimented a bit in
query analyzer.
Considering overhead to convert all data in my app to decimal, I can use
ROUND() on calculations.
>I would use DECIMAL not FLOAT for financial data.
> http://www.aspfaq.com/2477
>
>
>
>
>> Hi,
>>
>> I am developing a web based application that deals with financial info
>> (coldfusion and sql server 2000 on shared server). All the numbers that
>> carry this info are of float data type. I ran into a situation when this
>> gives all kind of problems.
>>
>> For example, I calculate cost after very small update of a salary and
>> cost may not increase notisably on the interface because there is always
>> a mask rounding up to 2, 3 or 4 digits depending on a setting. But most
>> of data manipulations, like creattion of adjustments are done in stored
>> procedures and the difference in new cost may be so small that rounding
>> up to 11 digits will give me a difference not less. Which in turn is
>> saved in db as a record that displayed later on the interface with the
>> value of $0 rounded to 3 digits.
>>
>> So, I am just wondering, should I use ROUND() function in the stored
>> procs and queries on calculations with the argument set to 2, 3 or 4? Or
>> it is not safe with financial data?
>>
>> Thanks,
>>
>> Gene
>>
>
>
|
|
|
|
|
Aaron
|
Posted: Wed Feb 22 16:11:22 CST 2006 |
Top |
SQL Server Developer >> Help with float data type
> Well, with decimal I still have to specify number of digits to round to,
> otherwise in many case it will default to integer.
If your columns are specified in DECIMAL(whatever) you won't have to do any
conversions or hard-coding of decimal places at all.
|
|
|
|
|
|
|