I want to type cast in openlaszlo? - openlaszlo

I want to type cast in openlaszlo if any one work on it then tell me. One big task is pending for that smaller issue. It immediate. when i compare 2 digit number it get only first digit.

Number(variable) it working if you want to compare two number more than one digit then you must use Number for type casting otherwise compiler treat that number as a one digit number and u might be get wrong output.

Related

Alteryx separate the first integer of a number and put it in a new column

I only have one column that has an 8-digit number. No dots, commas or any conjugation. Only integers.
I simply want to extract the first integer from the number and put it to a new column named "First integer". I want the rest of the integers, untouched, to either go to a new column as they are, or stay in the existing column but without the first integer
for example now I have: columnA: 23456789
I want First Integer:2 columnA: 3456789
I am pretty new to Alteryx so that might even be a ridiculous question to some :P
But any help is greatly appreciated :)
Suppose [i] is the relevant numeric field in your Alteryx workflow.
Then using a Formula tool, this expression will give the first digit:
[i]/POW(10,FLOOR(LOG10([i])))
And this will give the remaining digits:
MOD([i],POW(10,FLOOR(LOG10([i]))))
Explanation: working inside-out: Log10([i]) tells you how many powers of 10 you're working with, FLOOR just rounds that off, POW(10,...) multiplies it back out... so basically for an 8 digit number, this gives 10,000,000. Then you simply divide to get the first digit, or take the MOD (modulus) to get the remaining digits.
PS, your question mentions an 8-digit integer... if you are absolutely certain that your integers always have 8 digits (and the first digit is not a zero), then you can shortcut this: firstDigit=[i]/10000000 and remainingDigits=MOD([i],10000000).

String parsing in optimal way

Suppose I have a string as onehhhtwominusthreehhkkseveneightjnine
Now I want to parse this string to get the numbers out of it. For Example this string should return an array, [one,two,minusthree,seven,eight,nine].
The order of the Integers should be maintained.
Can anyone Please suggest an optimal way to do this parsing? Thanks.
(You haven't mentioned a programming language?)
I would probably search for "minus" and check the number(s) that follow it. Then search for "one", then "two", noting their indexes. This would provide enough information to map and output the results, and order, that you need.
Another option is to look at each character in order, comparing each to the 10 choices. I couldn't tell you which is the most efficient - I think it depends on the possible total string length. I'd probably write both and profile them.
If the string to search is not of inordinate length then I suspect that the second approach might be more efficient. This is because, as soon as you have a match, you can eliminate searching the following (known) length of characters.
That is, if you have "abceightd", once you discover the "e" and its "eight" you can skip four characters. You can also skip the a, b, and c anyway, as they are not the beginning character for any of the 10 choices.
I am assuming your choices are:
one, two, three, four, five, six, seven, eight, nine, minus
Assuming that a) you have access to regular expressions in your choice of programming language and b) your possible choices are as Andy G has assumed... then this regular expression can pick out the numbers grouped with their associated minus, if present:
/((?:minus)*(?:one|two|three|four|five|six|seven|eight|nine))/g
Applied to your example string using JavaScript's RegEx.exec(), for example, this extracts:
one
two
minusthree
seven
eight
nine
You could easily place a space after any minus matched if required. Does this help at all?

How can I change positive value to zero in Excel

I have two columns for the time in and time out of the employee, and I want to determine their lates and undertimes. But I cannot properly do it, I already can do the negative value to zero but I just want to know how to do the positive value to zero.
This is my formula =(G10-C10)*1440 then as per my column values it will show a positive value but I want the positive value become ZERO
Thanks!
You could use IF, which would be the most popular choice:
=IF(G10-C10>0,0,(G10-C10)*1440)
Could be read as, 'if the difference is greater than 0 (positive), then put 0, otherwise put the difference itself'.
Or a little less common, but simpler:
=MIN((G10-C10)*1440,0)
As an alternative to Jerry's answer, after applying your original formula, you can change the format of the cells to something like this:
"0";-0;0
The first 0 is for positive. The quotes around it make sure the zero gets displayed literally.
The second section (each section separated by a semi-colon ;) is for negative and the last one's for zero values.
The zero without quotes here means that one number should get displayed compulsorily.
Here's the output:

Excel-VBA UDF: Keep 2 values but display only 1

I wrote a user-defined function for fractions to be displayed with superscripted & subscripted digits (available in Unicode), with denominator no more than the user wants to. I could basically turn π into ²²/₇ with "=Fraction(PI(),30)", since no other fraction would be closer to π with a denominator smaller than or equal to 30.
Then I'm thinking of writing an InvFraction function as well, to get from a string generated by the Fraction function into an actual number. As you can imagine, though, the value is not π anymore, but 3.142857... (i.e. ²²/₇). So I'm postponing the writing until I remove that sense of chasing a ghost I'm feeling about it.
I saw that one could make the Fraction function generate a size-2 array of values, then through the index function, let the user decide which one to display, or enter the Fraction function as an array function covering 2 cells. Neither one is ideal from my perspective, the first option because the second value, which could be π, gets lost through the index choice and is no longer retrievable, the second option because it forces two cells to contain the data (though I guess I COULD end up living with it).
I also thought of using user-defined types containing the string value for the fraction and the double value for the original input, but I noticed they don't work in the actual sheet, then informally confirmed the info there: Call VBA function that returns custom type from spreadsheet
Anyone would have any idea at how to tackle this? Thanks anyways for having taken the time to read.
Edit: To put it simply, if I were to program the InvFraction function as I conceived it with the tools and ideas I have, I could only manage to have “=InvFraction(Fraction(PI(),30))” to equal 3.142857... (22 divided by 7), but I would rather like it to generate 3.14159265... (π).

Trying to show only a certain amount of numbers

To make the sale to my customer I need to import numbers from a report into an Excel document. For example the number coming in will be 14.182392. The only reason for my guy not to buy the product is because he only wants to view 14.182 on the Excel sheet. Okay so the other catch is, the number CANNOT be rounded in any shape or form.
So what I need is a way to just show so much of number, WITHOUT ROUNDING.
Is this possible? Any ideas of how I could get around this would be fantastic.
Please try:
=TEXT(INT(A1)+VALUE(LEFT(MOD(A1,1),5)),"00.000")
Firstly =TRUNC is a better answer (much shorter). My version was connected with uncertainty in your requirement (it is odd!) and in the hope it might be easier to adjust if not exactly what you/your boss wanted.
TRUNC literally just truncates the decimals (no rounding!) to a length to suit (ie 3 if to show nn.182 given nn.182392 or say nn.182999).
LEFT may also be a better choice, but that depends upon knowing how large the integer part of your number is. =LEFT(A1,6) would display 14.189 given say 14.189999 in A1. However it would show 1.4189 given 1.4189999 in A1 (ie four decimal places).
The formula above combines text manipulation with number manipulation.:
INT takes just the integer value (here 14.)
MOD takes just the modulus – the residual that is not an integer after division, in this case by 1. So just the .182392 part. LEFT is then applied here in a similar way to as used above, but without needing to concern oneself with the length of the integer part of the source value (ie 14 or 1 etc does not matter).
VALUE then converts the result back into numeric format (string manipulation functions such as LEFT always return text format) so our abbreviated decimal string can then be added to our integer.
Finally, the TEXT part is for formatting but is hard or impossible to justify! About the only use is that it displays the result left-justified in the cell – perhaps a little warning that the number displayed is not the “true” value (eg it won’t SUM) because, as a result of a formula, it won’t be marked with a little green warning triangle.
The displayed values can use the TRUNC function like this,
=TRUNC(A1, 3)
But you must use A1 in any calculations to retain the precision of the raw value.
Easiest way I know:
=LEFT(A1; x)
where x = the amount of characters You want. Mind that the dot counts as a character as well.

Resources