Decimal database values are rounded incorrectly when saving

Description

Issue described here:

http://discourse.farcrycore.org/t/fc7-not-saving-numeric-data-after-decimal-when-using-dbprecision-and-type-numeric/697

I have run into this as well. Occurs when using sql server and a content type like this:

```
<cfcomponent output="false" extends="farcry.core.packages.types.types" displayname="Test" hint="" bFriendly="false" bObjectBroker="true">
<cfproperty
ftSeq="110"
ftFieldset="General"
ftLabel="Fee"
name="fee"
type="numeric"
ftType="numeric"
default="0"
ftDefault="0"
required="true"
ftIncludeDecimal="true"
dbPrecision="18,2"
/>
</cfcomponent>
```

deploy it, then run this test script

```<cfscript>
o = application.fapi.getcontenttype("spcTest");

st = {
fee = 149.99
};

result = o.createData(o.beforeSave(st, {}));
o.afterSave(o.getdata(result.objectid));
newst = o.getData(result.objectid);
writedump(var = newst);
</cfscript>
```

For me, it rounds the 149.99 up to 150 when saving.

I have narrowed this down to a core issue. Core uses `cf_sql_decimal` without passing the `scale` attribute to `cfqueryparam` so it uses the default scale of 0 which causes SQL Server to round it.

The best solution would be for core to pass the scale parameter based on the dbPrecision you specify when you create the property. I imagine that `getValueForDB()` in the various gateways should be modified to also include a `scale` key in the result struct, and then when those are passed to `cfqueryparam` instead of setting them individually simply change it to `<cfqueryparam attributecollection="#stVal#" />` where `stval` is the result from `getValueForDB()`.

In the meantime, I have fixed this by overriding the DB Gateway and modifying `getValueForDB()` so that if it is one of the various currency properties we are using, I change it to `cf_sql_float` if I see `cf_sql_decimal`.

I'm also going to log this as a bug in Jira.

Environment

None

Activity

Show:
Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Created February 10, 2017 at 5:29 PM
Updated February 16, 2017 at 5:58 AM
Resolved February 16, 2017 at 5:58 AM