I would like to display a number according to the position of the first uncertain digit.
Hence for a number as 203.32134 with the first uncertain digit being 0.01 I would like to display 203.321 (all the certain digits plus the first uncertain as is and the second rounded.)
But I do not know how I could write a string format with a %x.yf in order to get my string as I would like.
Could anyone help?
Use NSNumberFormatter and set minimum/maximum number of significant fractions.
Related
Something strange is happening with the sorting. I am sorting G (weight) from smallest to largest. The numbers are 1 to 41.
It doesn't sort starting from the number 1. Instead the order is 10,11,12,13,14,15,16,17,18,19,2,20,21,23,25,26,3,30,35,4,41,5,6,7,8,9.
I know technically 10 starts with the number one, but shouldn't this application be smart enough to know that you don't start counting at number 10? The smallest weight of 2 should be first, followed 3,4,5,67,8,9,10,11,12,etc.
Is this not possible with that sorting option?
try to multiply your G column with 1 to convert your string numbers into numeric numbers as of, you are sorting it now by alphabetical order 10,1,20,2 not numerical 1,2,10,20
It sounds like your Col-G weights are strings and not actual numbers. And assuming that is the case, Google sorts in order according to ASCII char numbers. If you have any non-numeric characters appended (e.g., "kg"), then you've created strings automatically. However, if you only have digits and they somehow got into your sheet as strings (which are not actively generated by formula), you can try selecting that column and choosing Format > Number > 0.
I need to count the number of digits in an SPSS numeric variable, and assign it to a different variable.
I tried converting it to a string and counting the length of the string with char.length(), but this returns the defined length of the variable, rather than the length of the actual string in each line.
Any ideas how this can be done?
when canculating the length of your string variable, use ltrimor rtrim(depending on how you calculated your string - just to be sure you could use both) to get rid of spaces and count only digits:
compute Ndigits=char.length(ltrim(rtrim(YourString))).
you could also do away with the text variable altogether and just use this function:
compute Ndigits=trunc(lg10(YourNumber))+1.
Note that the length will depend on how the number was converted to a string, i.e., the number of decimals specified in the conversion. Also, the decimal point character will contribute to the length.
Also, if you are in Unicode mode, which has been the default for several years, you don't need to use char.rtrim. Strings are automatically rtrimmed in that mode.
I have a sheet with values that I want to format in grams. The values range from high to low and I wish to format them with a comma as a thousand-separator, and rounded to two decimal places, but trimming both the decimal point and places where the number is a whole number. The following examples should explain better:
1000 to be presented as 1,000g
0.75 to be presented as 0.75g
0.2 to be presented as 0.2g
0.1234 to be presented as 0.12g
I've tried using a custom number format of #,##0.##g but this does not satisfy my first requirement (a) where the numbers are whole numbers and leaves an insignificant decimal point (i.e. 1,000.g), although does very well at formatting the remaining three requirements (b, c and d).
Is there a way of overcoming this?
#,##0.00_ g;(#,##0.00 g)
I'm a bit late to this article but I found the above format works for me.
Assuming your numbers are in column A with a header. You could try putting this in B2 then hide column A:
=arrayformula(if(arrayformula(TRUNC(A2:A,2)&"g")="0g","",arrayformula(TRUNC(A2:A,2)&"g")))
The best I could do with format was [=0]0;.## It gets rid of the period in 1000 but does not truncate 0.1234 and doesn't add the g. Maybe you could work with that if you must use format. I really don't think format can do it.
I have a function that returns a float value like this:
1.31584870815277
I need a function that returns TRUE comparing the value and the two numbers after the dot.
Example:
if 1.31584870815277 = 1.31 then ShowMessage('same');
Sorry for my english.
Can someone help me? Thanks
Your problem specification is a little vague. For instance, you state that you want to compare the values after the decimal point. In which case that would imply that you wish 1.31 to be considered equal to 2.31.
On top of this, you will need to specify how many decimal places to consider. A number like 1.31 is not representable exactly in binary floating point. Depending on the type you use, the closest representable value could be less than or greater than 1.31.
My guess is that what you wish to do is to use round to nearest, to a specific number of decimal places. You can use the SameValue function from the Math unit for this purpose. In your case you would write:
SameValue(x, y, 0.01)
to test for equality up to a tolerance of 0.01.
This may not be precisely what you are looking for, but then it's clear from your question that you don't yet know exactly what you are looking for. If your needs are specifically related to decimal representation of the values then consider using a decimal type rather than a binary type. In Delphi that would be Currency.
If speed isn't the highest priority, you can use string conversion:
if Copy(1.31584870815277.ToString, 1, 4) = '1.31' then ShowMessage('same');
I want to check if the number pin user entered is too simple. 3 cases would fail, repeating numbers, like "1111"; increasing ones like "1234"; decreasing ones like "4321". Is there a regex which could check these restrictions?
Regex can match specific text pattern but it can't understand its context..Yes you want to check for increasing numbers but there's no such thing as increasing pattern in regex.
You can check for repeated numbers using ^(\d)\1+$
But to check for increasing,decreasing numbers you would have to parse the string to int and check if they are in increasing or decreasing order manually using the %,/ operations