Mysql has the different integer datatype like, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT. Is there any way to detect the number is falling under which data type in JavaScript?
Asked
Active
Viewed 367 times
0
-
i would just hard code it with greater than and less than – Roland Starke Sep 06 '19 at 15:01
-
@RolandStarke — That could tell you the smallest DB datatype that would hold the number you had, but it wouldn't tell you the actual datatype. – Quentin Sep 06 '19 at 15:02
2 Answers
1
JavaScript only has one datatype for numbers: Number
(BigInt is proposed for a future version of JS).
So, all else being equal: You can't.
Your database API might provide a mechanism that would expose that information, but it would depend on the database API you were using.

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
Thanks @Quentin. Actually I am creating the YAML file by reading the CSV input (using node js). So in the `type` attribute I have to mention the number data type. – mkHun Sep 06 '19 at 15:03
0
In JavaScript, there is no such categorization as such int or float, there is only number, more details about datatypes in JavaScript here.
Further if you need to check weather the value is int of float, you can the answer in following link here

Nikhil Kinkar
- 761
- 8
- 31