How do we know the Length of numeric field with decimal plac

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

How do we know the Length of numeric field with decimal plac

Post by khurshid.arshad »

Gregory
I want to know the length of this value. How can i do? I want to use this syntax for GPS Coordinates.

Numeric xyz;
Alpah abc;


xyz=Maketext("%d",12.3456);

abc=length (strip(xyz));

errmsg ("%d", abc);

Regards.

arshad
pierrew
Posts: 47
Joined: August 8th, 2012, 5:20 am
Location: Pohnpei, Federated States of Micronesia

Re: How do we know the Length of numeric field with decimal

Post by pierrew »

Hello ...

Use %f to write a floating point into text. Be aware that it is limited to, I believe, 6 places before the decimal. So if you only have 2 digits, the "%f" will automatically add 3 more zeros. So your value of 12.3456 will contain a length of 9 -> [12.345600]. Oh and its NUMERIC abc and ALPHA xyz below.

I hope this helps.

Pierre
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How do we know the Length of numeric field with decimal

Post by Gregory Martin »

I'm not sure I understand the question. Are you trying to find out how many digits after the decimal your value has, or are you trying to print it out with a certain number of digits after the decimal?

If the latter, you can use Pierre's %f suggestion. You can also specify the number of digits that you would like. For example, if you want four digits after the decimal point, you could write:
errmsg("%0.4f",VALUE);
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How do we know the Length of numeric field with decimal

Post by khurshid.arshad »

Dear Gregory

I am trying to find out how many digits after the decimal or total number of digits with decimal/without decimal. I have already try all these options. I don't want to add extra zeroz. ("%d"; "%f"; "%0.5f";etc.)

My data is 12.345
errmsg("%0.4f",VALUE);
Value = 3450(length is 4)
Actual length is 3 not 4 after decimal
I want to know the length is "3"

My data is 12.34
errmsg("%0.4f",VALUE);
Value = 3400(length is 4)
Actual length is 2 not 4 after decimal
I want to know the length is "2"


Regards.

arshad
pierrew
Posts: 47
Joined: August 8th, 2012, 5:20 am
Location: Pohnpei, Federated States of Micronesia

Re: How do we know the Length of numeric field with decimal

Post by pierrew »

Try this ...

Code: Select all

num = 12345678.1234567891;
nomi = length(strip(maketext("%d",num)));
//get rid of decimals
denomi = int(10000000000 * (num - int(num)));
//get rid of zeros
do until (denomi/10) <> int(denomi/10)
	denomi = denomi / 10;
enddo;
denomi = length(strip(maketext("%d",denomi)));
errmsg ("nomi size:%d demoni size:%d", nomi,denomi);
There might be an easier way. =)
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How do we know the Length of numeric field with decimal

Post by khurshid.arshad »

Dear pierrew;

Thanks for your input. I have tried your syntax but problem is still there.

We are going to conduct a survey in 18 districts. For this survey we are using GPS. Our format is "Longitude dd.ddddd; Latitude dd.ddddd".

I want to see whether KPO enter all the digits or not. If kpo type only 12.34 and he missed last three digits the message shows "denomi size is 10" in your syntax. But in this example "Denomi size is 2". Another example: KPO type 12.3450 and missed last digit(fifth-one). If i run your syntax the message shows that "denomi size is 3" which is wrong . In this case your syntax eliminate last zero which is wrong. The zero is fine actually fifth digit is missing.

I just want to know that KPO enter all the digits after the decimal or not(after the decimal length size is 5).

Regards.

Arshad
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How do we know the Length of numeric field with decimal

Post by Gregory Martin »

If these values are numeric, you will never be able to accomplish this task because:

1) CSPro automatically zero fills the numbers to the right of the decimal.
2) Because of this, you will not be able to tell if these zeros were actually keyed by the keyer or if they result from zero filling.

You could make the value alphanumeric and then use the pos command to figure out where the decimal point is, and then see how many characters were entered after the decimal point, but if you do this, you'll have to ensure that valid values are being entered (because the enumerator could enter letters, for example).

Alternatively, if you want to get fancy, you could override OnChar, doing something like this:
PROC GLOBAL

numeric numbersAfterPeriod;
numeric firstTimeEntering;

function OnChar(keystroke)

    
if keystroke = 46 then // period
        numbersAfterPeriod = 0;
        
    
elseif keystroke in 48:57 then // numbers
        inc(numbersAfterPeriod);
    
    
elseif keystroke = 8 then // backspace
        inc(numbersAfterPeriod,-1);

    
endif;

    OnChar = keystroke;

end;


PROC LATITUDE

onfocus

    firstTimeEntering = (
visualvalue(LATITUDE) = notappl );

postproc

    
if firstTimeEntering and numbersAfterPeriod <> 5 then
        
errmsg("Enter all five decimal points.");
        
reenter;
    
endif;
    
    
The firstTimeEntering flag allows the program to skip this check if the keyer is just skipping by a field that was already entered.
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How do we know the Length of numeric field with decimal

Post by khurshid.arshad »

Dear Gregory;

Thanksssssssssss and take care.

regards.

arshad
pierrew
Posts: 47
Joined: August 8th, 2012, 5:20 am
Location: Pohnpei, Federated States of Micronesia

Re: How do we know the Length of numeric field with decimal

Post by pierrew »

Hello Arshad,
I think the easiest way is to build you dictionary into 7 dictionary items
e.g.,

digit1 - LEN:1 VALSET:0:9
digit2 - LEN:1 VALSET:0:9
...
digit7 - LEN:1 VALSET:0:9

on the form ...
[ ][ ].[ ][ ][ ][ ][ ]

Pierre
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How do we know the Length of numeric field with decimal

Post by khurshid.arshad »

Dear;

Thanks for your input. I am using Gregory's syntax and it works perfectly after small change. I am not using onfocus option.



//onfocus

// firstTimeEntering = ( visualvalue(LATITUDE) = notappl );


if numbersAfterPeriod <> 5 then
errmsg("Enter all five decimal points.");
$=notappl;
reenter;
endif;



Regards.

arshad
Post Reply