question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Real numbers get rounded.

See original GitHub issue

When I try to insert a field with a real number, it gets rounded down in the table.

F.e.

let v = 8.5
sql.query`INSERT INTO Table (columnName) VALUES (${v})`

Then the new record gets a value of 8 instead of 8.5, while the type of columnName is set to real.

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 vs real).

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

3reactions
patriksimekcommented, Oct 18, 2016

You can override default type for each input parameter.

request.input('decimal', sql.Decimal(38, 10), 4.23)
0reactions
xinthosecommented, Feb 22, 2021

My issue was not specifying the precision and scale in the data type, without it, the library rounds the decimal apparently: .input("pH", TYPES.Decimal(12, 2), spData.pH)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rounding Numbers - Math is Fun
Rounding means making a number simpler but keeping its value close to what it was. The result is less accurate, but easier to...
Read more >
Rounding Real number - Mathematica Stack Exchange
I have real numbers in array, I want to round (or truncate) these numbers to 2-digit after decimal point, then I want to...
Read more >
Rounding Decimals - Varsity Tutors
To round a number to the nearest tenth , look at the next place value to the right (the hundredths). If it's 4...
Read more >
Rules, Examples for Rounding Numbers - Cuemath
Numbers can be rounded to different digits, like, they can be rounded to the nearest ten, hundred, thousand, and so on. For example,...
Read more >
Rounding Numbers - Rules & Examples For Fractions & Sums
When rounding a number, you first need to ask: what are you rounding it to? Numbers can be rounded to the nearest ten,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found