Home > Back-end >  Change the value of an object to Long
Change the value of an object to Long

Time:10-24

I want the value of the object to be not a double type but a Long type.

client.db("customDB").collection("chart").insertMany( [{"chart": data.chart}]...


  "chart" : [ 
    {
        "x" : 1635017640000.0, ----->   1635017640000 (LONG NUMBER)
        "y" : [ 
            0.13715, 
            0.13715001, 
            0.13714999, 
            0.13715
        ]
    }
 
]  

Thank you :)

CodePudding user response:

parseInt(1635017640000.0) would be the way to go :)

No need to import anything.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Remember to google the issue - in javascript any floating point number is called float and any number without comma is an int or rather "integer"

CodePudding user response:

You can use Math.floor to convert to an integer and strip the fraction.

The Math.floor() function returns the largest integer less than or equal to a given number.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor

{
  x: Math.floor(123.456)
}
  • Related