I have a raster with float number values for example: 2.544459104537964 and I want to round these up to integers. I have seen other posts on ArcGIS like this one but when I use Raster Calculator in QGIS, Int(myraster + 0.5) only makes the first value (which is 0) to 0,5 and the last one (which is 100) to 100,5. The other pixels stay float.


This is a bit of a hack but it works: The QGIS raster calculator does not support rounding as far as I know but you can use GDAL to perform float to int type conversions.

  1. Raster -> Conversion -> Translate

    • change the datatype from float to int by using the -ot option

    • gdal_translate -of GTiff -ot Int32 E:/float.tif E:/int.tif

  • 1
    OMG this worked perfectly! Values such as 3,391823765 are now 3 and values like 5,912735176253 are now 6! thank you so so so much
    – Stelios M
    May 8 '15 at 18:03
  • Wait, so it doesn't allways round down? Am I missing something in the documentation here?
    – Kersten
    May 8 '15 at 19:21
  • To me it rounds them up as it should: 0,5 and above decimal becomes 1 and 0,4 and below becomes 0! And actually, after that I wanted the image to be grayscale. At first I typed -ot Int32 as you said, but then I had issues with the image in image processing software like Gimp. It showed as a 1 band RGBA. So I searched the documentation and I tried -ot Byte. Then it worked like a charm. Thanks again for this!
    – Stelios M
    May 8 '15 at 19:36
  • Perfectly! I have already read many answers and no one did correctly operation. Thank you. Jul 15 '15 at 0:40
  • odd that QGIS doesnt have that option in the dialog box
    – chrismarx
    Dec 14 '16 at 15:49

The answer given by @Kersten is still good six years on. I didn't get it right first time though, so just to save anyone else similar problems, here are some more details for QGIS 3.10. The tool is currently in Toolbox > GDAL > Raster conversion > Translate (convert format). The -ot option goes in the dialogue box, but you also need to specify the data type you want to convert to. Like so:

enter image description here

Other options are available:

enter image description here Source - https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/gdal/rasterconversion.html#translate-convert-format

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.