integer and decimal

gasomma

Member
Hello,

I tried searching but i didnt find anything that would help me with my situation so here is my question...

I want to separate in two different integer fields a decimal value.
Ex.

value=6.73
field1 = 6
field2 = 73

have in 4gl a function for that?
Thx
JCA
 
This seems to do what you are asking:


def var decnum as dec init 56.3.

disp int(truncate(decnum,0)) int( ((decnum - truncate(decnum,0)) * 100) ) .
 

Cringer

ProgressTalk.com Moderator
Staff member
Alternatively

disp int(entry(1,string(decnum),".")) int(entry(2,string(decnum),".")).

should work.
 

Stefan

Well-Known Member
Alternatively

disp int(entry(1,string(decnum),".")) int(entry(2,string(decnum),".")).

should work.

Actually it depends. You are assuming that the decimal point is a point, you can easily remove the assumption with:

Code:
disp int(entry(1,string(decnum),SESSION:NUMERIC-DECIMAL-POINT)) int(entry(2,string(decnum),SESSION:NUMERIC-DECIMAL-POINT)).

Then you run into the next assumption that the decimal will always have a decimal part. Which can then be worked around:

Code:
disp int(entry(1,string(decnum),SESSION:NUMERIC-DECIMAL-POINT)) int(if num-entries( string( decnum ), session:numeric-point ) = 2 then entry(2,string(decnum),SESSION:NUMERIC-DECIMAL-POINT) else 0 ).

But its a bit of a mess, so I'd stick to much cleaner truncate version.
 
Top