Hi,
I would like to determine the number of digits in a decimal number
For instance :
real a = 31.250
int b ;
I would like the réusltat either b = 5 ( the number of digits in a)
Is there a function to perform this calculation ?
Thanks.
Hi,
I would like to determine the number of digits in a decimal number
For instance :
real a = 31.250
int b ;
I would like the réusltat either b = 5 ( the number of digits in a)
Is there a function to perform this calculation ?
Thanks.
the result either*
Combine two functions - one to remove non-digit characters and one to count the length:
b = strLen(strKeep(a, '0123456789'));
I just tried your solution in my situation :
b = strLen(strKeep(inventTable.grossDepth, '0123456789'));
but the first parameter must be of type text and grossDepth is not a text type... Maybe i didn't understand something ?
As you said its a “real”, convert to string and find the length.
real a = 31.250;
str s= num2str(a);
int l;
;
l= strlen(s);
info(strfmt("%1", l);
returns 5
it should be something of this type.
b = strLen(strKeep(a, inventTable.grossDepth));
If you start with a real number, then the number of digits depends on how you convert the number to string. For example, it could be “31.25” instead of “31.250” and you would get 4 instead of 5.
Maybe you should think again about what you actually want to achieve.
try this
l =
strLen(num2str(inventTable.grossDepth,1,2,1,0));
In my case i want the number of digits in inventTable.grossDepth so in my example a is inventTable.grossDepth
You need to convert the field “inventTable.grossDepth” to str as the strkeep function takes string as the first argument.
Your solution seems to work well AnandMallavarapu7.
Thanks you very much guys.
The verified suggestion returns the right result by mere coincidence. Look at it again:
strLen(num2str(inventTable.grossDepth,1,2,1,0));
It converts the number to something like “31.25” and then it counts the length. It returns 5 because there are four digits and one decimal point. It’s definitely not the same thing as counting the number of digits!
Yes , sorry I misspoke , it was not the number of digits , but the number of characters that I wanted …
So the solution was actually quite simple