2

I want to round off an ee.Number() object to two decimal places. Right now I am using .toFixed() of JavaScript, but how to do that using a server-side function? I tried toFloat() but that doesn't help.

2

It seems to work as follows, though I am unsure if this is proper rounding within the GEE:

// make an ee.Number with more than 2 decimals
var number = ee.Number(76.457034897543523)

// round to two decimals using divide/multiply
var rounded = number.multiply(100).round().divide(100)

// format to string and make string a number
var rounded2 = ee.Number.parse(number.format('%.2f'))
1
  • Thanks, serves the purpose
    – shahryar
    Oct 25 '20 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.