# Compare integers of a decimal value

**URL:** <https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [November 28, 2016, 7:05am UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801 "2016-11-28T07:05:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![V\_M1](https://avatars.discourse-cdn.com/v4/letter/v/a6a055/32.png) [@V\_M1](https://techcommunity.softwareag.com/u/V_M1)\
**Post date:** [November 28, 2016, 7:05am UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/1 "2016-11-28T07:05:03Z")

</div>

Hello All,

I want to compare the integer values of a decimal number. Fr eg - I want to compare 123 and 435 from 123.1212 and 435.3333.  
Is there a way to get only integer value into a numeric field. I know the separate command but for that I need the input values as Alpha numeric. Also once separated the output will be in Alphanumeric field.

Please let me know the simplest possible way.

Thank you,  
VM

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [November 28, 2016, 8:31am UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/2 "2016-11-28T08:31:40Z")

</div>

Natural has a function to extract the integer portion.

```auto
DEFINE DATA LOCAL
1 #N (N3.2) INIT <22.11>
1 #P (P2.3) INIT <22.222>
END-DEFINE
IF INT (#N) = INT (#P)
  THEN
    WRITE 'integer portions are equal' #N #P
END-IF
END
```

```auto
Page 1 16-11-27 23:29:21
 
integer portions are equal 22.11 22.222
```

---

<div class="post-metadata">

**Author:** ![V\_M1](https://avatars.discourse-cdn.com/v4/letter/v/a6a055/32.png) [@V\_M1](https://techcommunity.softwareag.com/u/V_M1)\
**Post date:** [November 28, 2016, 9:32am UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/3 "2016-11-28T09:32:08Z")

</div>

Hi Ralph,

Thanks so much. Never knew of the INT function. Your code is what I am exactly looking for. I used edit mask to move it to alpha numeric. Then used separate with delimiter ‘.’ But again I have it in alpha which I had to move to Numeric. But the below serves the purpose in a single step.

Regards,  
VM

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [November 28, 2016, 1:13pm UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/4 "2016-11-28T13:13:17Z")

</div>

I am quite surprised that you would consider SEPARATE, but not the far more obvious code shown below:  
DEFINE DATA LOCAL  
1 #N (N3.2) INIT \<22.11\>  
1 #P (P2.3) INIT \<22.222\>  
1 #NI (I4)  
1 #PI (I4)  
END-DEFINE  
\*  
COMPUTE #NI = #N  
COMPUTE #PI = #P  
IF #NI = #PI  
THEN  
WRITE ‘integer portions are equal’ #NI #PI  
END-IF  
END

I was not surprised you did not know about INT. There are MANY Natural facilities, functions, capabilities that remain unknown to the vast majority of Natural programmers (education, education, education).

One more note; many Natural functions are quite expensive. Following is a timing comparison.

```
DEFINE DATA LOCAL  
1 #N (N3.2) INIT <22.11>  
1 #P (P2.3) INIT <22.222>
1 #NI (I4)
1 #PI (I4) 
1 #LOOP (I4)

```

1 #CPU-START (I4)  
1 #CPU-ELAPSED (I4)  
END-DEFINE  
\*  
MOVE \*CPU-TIME TO #CPU-START  
SETA. SETTIME  
FOR #LOOP = 1 TO 300000  
IGNORE  
END-FOR  
COMPUTE #CPU-ELAPSED = \*CPU-TIME - #CPU-START  
WRITE 3/10 ‘CONTROL LOOP TIME==\>’ \*TIMD (SETA.) #CPU-ELAPSED /  
\*  
MOVE \*CPU-TIME TO #CPU-START  
SETB. SETTIME  
FOR #LOOP = 1 TO 300000  
IF INT (#N) = INT (#P)  
IGNORE  
END-IF  
END-FOR  
COMPUTE #CPU-ELAPSED = \*CPU-TIME - #CPU-START  
WRITE 3/10 ‘INT FUNCTION TIME==\>’ \*TIMD (SETB.) #CPU-ELAPSED /  
\*  
MOVE \*CPU-TIME TO #CPU-START  
SETC. SETTIME  
FOR #LOOP = 1 TO 300000  
COMPUTE #NI = #N  
COMPUTE #PI = #P  
IF #NI = #PI  
IGNORE  
END-IF  
END-FOR  
COMPUTE #CPU-ELAPSED = \*CPU-TIME - #CPU-START  
WRITE 3/10 ‘OWN INT FUNCTION TIME==\>’ \*TIMD (SETC.) #CPU-ELAPSED /  
\*  
END  
Page 1 16-11-28 06:50:29

```
     CONTROL LOOP TIME==> 0 4

     INT FUNCTION TIME==> 7 62

     OWN INT FUNCTION TIME==> 2 20

```

As shown above, using the INT function is three times as expensive as writing your own integer function (times are PC times; mainframe times are typically proportionate to PC times).

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [November 29, 2016, 4:33am UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/5 "2016-11-29T04:33:44Z")

</div>

Assuming your time is more valuable than the computer’s, just use  
COMPUTE #NUM = VAL(#STRING)

This presupposes that #STRING only contains valid numeric data. If it doesn’t, you can use the IS test -  
IF #STRING IS (N8) THEN  
COMPUTE #NUM = VAL(#STRING)  
END-IF  
Note that the IS test just checks that #STRING can be converted to the format given. Thus “123.41” will be true for I4, N3 (or any large N4+), P3 or larger, N or P format with any number of decimals. If won’t be true for anything smaller - P1, P2, N1, N2 will be false.

Anyways, assuming simple case of only valid data in #STRING…

```auto

DEFINE DATA                              
LOCAL                                    
01 #STRING1(A10) INIT<'123.41'>          
01 #STRING2(A10) INIT<'123.23'>          
01 #NUM1 (P7)                            
01 #NUM2 (P7)                            
END-DEFINE                               
*                                        
#NUM1 := VAL(#STRING1)                   
#NUM2 := VAL(#STRING2)                   
IF #NUM1 = #NUM2                         
  DISPLAY #NUM1 #NUM2                    
ELSE                                     
  WRITE T*#NUM1 #NUM1 T*#NUM2 'NOT EQUAL'
END-IF                                   
END                                      
```

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [November 29, 2016, 12:30pm UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/6 "2016-11-29T12:30:27Z")

</div>

Hi Doug;

VM wrote:

> [@](#):
>
> I know the separate command but for that I need the input values as Alpha numeric.

The assumption Ralph and I both made is that the source fields for the comparison are not Alpha but numeric (N or P).

Perhaps VM could confirm if our assumptions were correct. If so, the VAL function would not be appropriate.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:37pm UTC](https://techcommunity.softwareag.com/t/compare-integers-of-a-decimal-value/191801/7 "2021-04-02T15:37:25Z")

</div>


