# Thread: Help with math in function

1. Registered User
Join Date
Oct 2003
Posts
2

## Unanswered: Help with math in function

I have a function that reads an unsigned integer and translates it into an IP address. The problem is that it is rounding the numbers so the IP numbers are off by 1 either up or down, i.e., 144.xxx.xxx.xx will show as 145.xxx..... or 144.456.xx... will show as 144.455.xx.....Can someone help?

Here is the code:

create or replace function readip(unsint number)
return varchar
is
a number(3);
b number(3);
c number(3);
d number(3);

begin
a := mod( ( unsint / 16777216 ), 256);
b := mod( ( unsint / 65536 ), 256);
c := mod( ( unsint / 256 ), 256);
d := mod( ( unsint ), 256);

Thank you much!

Monica

2. Registered User
Join Date
May 2003
Posts
87
If you want the decimals to be displayed, define the variables as
a number(10,3);

Hope this helps.

3. Registered User
Join Date
Oct 2003
Location
Switzerland
Posts
140

## Re: Help with math in function

Originally posted by DBW-Monica
I have a function that reads an unsigned integer and translates it into an IP address. The problem is that it is rounding the numbers so the IP numbers are off by 1 either up or down, i.e., 144.xxx.xxx.xx will show as 145.xxx..... or 144.456.xx... will show as 144.455.xx.....Can someone help?

Here is the code:

create or replace function readip(unsint number)
return varchar
is
a number(3);
b number(3);
c number(3);
d number(3);

begin
a := mod( ( unsint / 16777216 ), 256);
b := mod( ( unsint / 65536 ), 256);
c := mod( ( unsint / 256 ), 256);
d := mod( ( unsint ), 256);

Thank you much!

Monica
Ì must be missing the obvious, but I just don't get it. Can you give an example of an input value, and what your function should return ?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•