GeoMedia Discussions

Search for an answer, post a question, or answer other users' questions in our GeoMedia support discussions. This discussion board is a great way to collaborate with industry peers around the world. It is intended for discussion and support of the GeoMedia Desktop and Add-on applications.
Showing results for 
Search instead for 
Do you mean 
Reply
Occasional Contributor
Posts: 6
Registered: ‎04-19-2017
Accepted Solution

Round to the nearest 0.5

Hi all,

In GeoMedia how can I round to the nearest 0.5?

Example:

45,64 -> 45,5

45,91 -> 46,0

43,81 -> 44,0

57,01 -> 57,0

56,33 -> 56,5

51,26 -> 51,5

35,43 -> 35,5

45,64 -> 45,5

59,29 -> 59,5

 

Thank you

Staff
Posts: 52
Registered: ‎01-25-2019

Re: Round to the nearest 0.5

 Does the ROUND operator help you, in Functional Attributes?

 

https://hexagongeospatial.fluidtopics.net/reader/rZHMZP5BYO6l8Rulw8Ns9g/CvvVo1TLMHBkR8qWB0FH6A

 

ROUND rounds a number to a specified number of digits.

Syntax

ROUND(number, num_digits)

Elements

number

I/O: Input R/O: Required DataType:I/O: Description: The number you want to round.

num_digits

I/O: Input R/O: Required DataType:I/O: Description: The number of digits to which you want to round number.

  • If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal places.

  • If num_digits is 0, then number is rounded to the nearest integer.

  • If num_digits is less than 0, then number is rounded to the left of the decimal point.

Return Type

gdbDouble

Technical Evangelist
Posts: 563
Registered: ‎09-11-2015

Re: Round to the nearest 0.5

This is a bit tricky I would say. Using ROUND it might be something like ROUND(2.0*x, 0)/2.0, or perhaps clearer would be FLOOR(2.0*x + 1.0)/2.0.

Technical Evangelist
Posts: 177
Registered: ‎02-02-2016

Re: Round to the nearest 0.5

Nice thing about the expression system is there's alternate ways of doing things... some methods better than others... I do NOT avocate this as being the most direct solution.

 

One way to think of the problem is that it's two conditional evalutions based on the value of the decimal portion of the value.

 

Condition 1: Decimal values >= 0.5, where the range is 0.5 to 1.0:
For these if the decimal value is closer to 0.5, then want the result to be Truc value + 0.5
if the decimal value is closer to 1.0, then want the result to be the Truc value + 1.0

 

Condition 2: Decimal values < 0.5, where the range is 0 to 0.5:
For these if the decimal value is closer to 0, then want the result to be Truc Value
if the decimal value is closer to 0.5, then want the result to be Truc value + 0.5

 

So with these conditions in mind in Functional Attributes you might try the following odd workflow..

In Functional Attributes build expressions:

 

FA_INT
TRUNC(Input.Source_Value)

 

FA_DEC
ROUND(Input.Source_Value - Output.FA_INT, 2)

 

The next part is bit messy so before building any further expression think out the logic from above to build two separate IF statements:
Syntax for IF:
IF ([Conditional test], [Value if True], [Vaue if False])

 

For Decimal values >= 0.5
IF(1.0-Output.FA_DEC >=0.25, Output.FA_INT+0.5, OUTPUT.FA_INT+1)

 

For Decimal values < 0.5
IF(0.5-Output.FA_DEC >=0.25, Output.FA_INT, Output.FA_INT+0.5)

 

You could do an attribute query divide and conquer in two different runs using the expressions above (which is probably what I would do to avoid wrapping my head around a nested IF statement) but.... if you want to put it altogether as a nested IF it might look like the following:

 

FA_Target_Values
IF(Output.FA_DEC >= 0.5, IF(1.0-Output.FA_DEC >=0.25, Output.FA_INT+0.5, Output.FA_INT+1), IF(0.5-Output.FA_DEC >=0.25, Output.FA_INT, Output.FA_INT+0.5))

 

Depth calculations for nautical charting?

Technical Evangelist
Technical Evangelist
Posts: 397
Registered: ‎02-03-2016

Re: Round to the nearest 0.5

Before seeing Pavel's answer I came to the same conclusion.  It's quite simple/elegant:

 

ROUND((MyFieldName*2),0)/2

 

Hal

 

Technical Evangelist
Posts: 177
Registered: ‎02-02-2016

Re: Round to the nearest 0.5

Arrggg.. sorry for the wind.. that's definitely a simple solution!  I thought I had tested Pavel's suggestion and noted that it did not always work but apparently my test was wrong.. perhaps I tested using FLOOR.

Occasional Contributor
Posts: 6
Registered: ‎04-19-2017

Re: Round to the nearest 0.5

Thank you all for your time and effort searching for an answer for my question.

Problem solved!

Regards.