LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Interger - Number of Digits

I have an interger which I do not want to exceed 2 digits.
Anything > XX should be returned as 2 digits or XX.
Example: 173 should be 73, 199 should be 99
 
Should I use a mask or modulus function ?
 
Thanks
Diego
0 Kudos
Message 1 of 3
(3,326 Views)
Hi,
for integer values you can use
    int i=199;
    int d;

    d=i%100;  //d2=99 ///two digits
    d=i%10;    //d2=9   //one digits
   
for float or double values you can use
    double d;
    double fint,frac;

    d=fmod(199.5,100); //d=99.5   two digits with fractional parts

  or if you not need fractional part of number
    frac=modf(d,&fint); //fint=99.0;frac=0.5
Message 2 of 3
(3,317 Views)

OVR_CZ... the interger example worked like a charm.

Thanks very much

Diego

0 Kudos
Message 3 of 3
(3,297 Views)