SQL Server Data Types

Asked

Viewed 149 times

1

I have a question about the type of data real in SQL Server.

I’m trying to store the value of 1.5 in a real type but it represents 1.5 as 1.5, wanted to know if when I was passing this value to a variable in Javascript would have any problem because of "," instead of "."?

1 answer

3


You’re confusing textual representation of the number with the number itself. If it will hold the number 1.5, it has no semicolon, it has an entire unit and half a unit in the decimal part. The semicolon is part of the textual representation, it depends on how you use it to display in SQL Server, but if you take the number it is only a number, it has an integer part and a decimal controlled by itself.

Any language that picks up the number will have the number correctly, and it’s up to the programmer to choose how to present it when necessary, in the middle of the process to make calculations do not have to worry about the character used to separate the decimal part because this does not exist.

But there’s a good chance you’re using a monetary value there, and there’s an error in two places, one in SQL Server and the other in Javascript (almost everyone makes this mistake and causes problems that aren’t always apparent). See more in What is the correct way to use the float, double and decimal types? and How to represent money in Javascript?.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.