Java Snippet and rounded geographic coordinates

Hello,

I wanted to round geographic coordinates so I wrote java code (in Java
Snippet node). I'm not an experienced java programmer.

Would by great if more experienced programmer could check my java
code. Node is working correctly but I don't know if it's a good and
efficient code.

My input coordinates have 7 digits after dot and I wanted 6 (with
trailing zeros). I used BigDecimal Class for accurate rounding and
Locale to change my default decimal separator. I attached my java
code (from node) and example input and output file.

Thanks,

Robert

 

Hi Robert,

the code looks fine.

However, I would just use the Round Double node. It can also convert double precision values into strings with fixed precision. Using Java Snippets is always more difficult to afterwards update the workflow.

Best, Iris 

Thanks for answer.

I used Round Double Node, but the result was wrong in some cases, example:

input: 49.6924825    19.2054788
output (Round Double Node, HALF_UP): 49.692482    19.205479
output (Java Snippet, BigDecimal rounding): 49.692483    19.205479

 

Best, Robert