-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Real numbers get rounded. #341
Comments
Meanwhile found in the docs that I can assign other SQL types to JS types. F.e. with But I do use other (integer) numbers in those queries. Is it advisable then to map the number type to real. And if so, why isn't it always done? |
US localization user here, and I've seen this issue occur similarly with decimal types.
Nope! It loses all precision this way and is basically an int.
Not an issue per se, as the workaround here wasn't too bad, but I thought it may help. Thanks for the great contribution to open source! |
I can't believe they always convert JS Number to Int. But it's a fact. And there is no "normal" way to fix this without pull-request. So here is my silly patch:
MSSQL is clever enough to convert decimal to int. So I tell him all Number are always decimal. |
To pass it in, (at least in 3.3.0), use a fixed length string in JS (which mssql will handle properly):
OR
|
It's not so simlpe, cause I'm using knex-js to work with MSSQL with some ORM lib on the top of knex. And to fix it in that way I have to make pull request to knex mssql dialect library. |
I wish I had an opportunity to set type mapper as a function which receives value as param, so I can manually detect correct type. But as I see, it's not possible for now. 'pg' driver allows developer to override default type detectors. And 'mssql' library - not. |
You can override default type for each input parameter. request.input('decimal', sql.Decimal(38, 10), 4.23) |
Cause I'm using knex lib on the top of mssql driver, I have no access to knex query compilation (without changing knex code), unfortunately |
Closing this one since it seems fixed inside knex. |
My issue was not specifying the precision and scale in the data type, without it, the library rounds the decimal apparently: |
When I try to insert a field with a real number, it gets rounded down in the table.
F.e.
Then the new record gets a value of
8
instead of8.5
, while the type ofcolumnName
is set toreal
.I think this is related to the decimal separator in MS SQL, as I'm currently working in a Dutch environment, and the decimal separator of the database is set to a comma instead of a period. So I guess the driver tries to do a conversion and ends up trunkating the result to the first period.
I also tried converting it to a string, and replacing the default JS period with a comma character, but then the query would not accept the value due to mismatch in types (
nvarchar
vsreal
).Edit: it doesn't happen when I include the value literally in the query. So it's probably related to the escaping of the query instead.
The text was updated successfully, but these errors were encountered: