Is it possible to round raster value in QGIS to a given number of digits? I have raster data with temperatures as values but the authors have made the values Celsius * 10. That is, a temperature of 2.5 is stored as 25. When I use the following formula in the Raster Calculator:

"july_merged@1" * .1

...the result is 2.599999904632568. I just want the 2.5.


As an alternative, you can use in QGIS the gdal.calc module located in : Processing toolbox > GDAL/OGR > GDAL - Miscellaneous > Raster calculator

  • Select your raster (A)

Raster Calculator - raster select

  • Type in the formula : round (A,2)

Raster Calculator - formula

The details of the function used comes from numpy array functions :

  • round_(a[, decimals, out]) Round an array to the given number of decimals.

This way, you can master the way the values are rounded. See below the result.

Raster Calculator - result

In a commandline way :

gdal_calc --calc "Round(A,2)" --format GTiff --type Float32 -A \\my\path\input.tif --A_band 1 --outfile \\my\path\output.tif
| improve this answer | |
  • 2
    gdal_calc --calc "Round(A,2)" - correct syntax may depend on Numpy version. For me round_(A,2) works with numpy 1.11. – jurajb Mar 19 '18 at 11:29
  • Hum...good point. Maybe i made a mistake in the final formula. I should check it out... From what I read in my own message (round_(a[, decimals, out]) Round an array to the given number of decimals.), i would say the right syntax is yours.. – gisnside Mar 19 '18 at 14:22

There's no built-in round function (which, ugh why), but this question provides a workaround - How to round up/down an pixel value of a raster to a pixel value with 2 decimal places?

In your case, replace multiply by 100 with multiply by 10 since you only want 1 decimal place.

| improve this answer | |
  • No, it still adds all of those decimal places. I tried all of the calculations on that page. – Jim Aug 14 '16 at 21:18

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.