How can I multiply a string.currency field in Freemarker? - netsuite

I have the following line of code on a Netsuite PDF/HTML:
${item.rate?string.currency}
I would like to multiply the output of this line by 1.1 to display as GST Inclusive however the only time it works is when i remove the "?string.currency" section.
When this is removed, I lose the currency formatting.
Any help is greatly appreciated.

Once you format a number as a currency (by using ?string.currency), you end up with a string which cannot be manipulated as a number anymore. So, do the manipulation first:
${item.rating * 1.1}
This will leave you with a number. To format the result as a currency, use brackets around the numeric part of the expression:
${(item.rating * 1.1)?string.currency}
See also:
https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_parentheses

Related

Excel: How to add two numbers that has unit prefixes?

I'm trying to add numbers that have the unit prefixes appended at the end (mili, micro, nano, pico, etc). For example, we have these two columns below:
Obviously doing something like =A2+A3+A4 and =B2+B3+B4 would not work. How would you resolve this? Thanks
Assuming you don't have excel version constraints, per the tags listed in your question. Put all the suffixes as delimiters inside {} delimited by a comma as follow in TEXTSPLIT, then define the conversion rules in XLOOKUP. We use SUBSTITUTE(col, nums, "") as input of XLOOKUP to extract the unit of measure.
=BYCOL(A2:B4, LAMBDA(col, LET(nums, 1*TEXTSPLIT(col,{"ms","us"},,1),
units, XLOOKUP(SUBSTITUTE(col, nums, ""), {"us";"ms"},{1;1000}),
SUM(nums * units))))
The above formula converts the result to a common unit of microseconds (us), i.e. to the lower unit, so milliseconds get converted by multiplying by 1000. If the unit of measure was not found it returns #N/A, it can be customized by adding a fourth parameter to XLOOKUP. If you want the result in milliseconds, then replace: {1;1000} with {0.001;1} or VSTACK(10^-3;1) for example.
If you would like to have everything in seconds, you can use the trick of using power combined with the XMATCH index position, to generate the multiplier. I took the idea from this question: How to convert K, M, B formatted strings to plain numbers?, check the answer from #pgSystemTester (for Gsheet, but it can be adapted to Excel). I included nanoseconds too.
=BYCOL(A2:B4,LAMBDA(col,LET(nums,1*TEXTSPLIT(col,{"ms","us"},,1),
units, 1000^(-IFERROR(XMATCH(RIGHT(col,2), {"ms";"us";"ns"}),0)),
SUM(nums * units))))
Under this approach, seconds is the output unit, because it is not part of the XMATCH lookup_array input argument, the multiplier will be 1 (as a result of 1000^0), so no units or seconds (s) will be treated the same way.
Notes:
In my initial version I used INDEX, but as #P.b pointed out in the comments, it is not really necessary to remove the second empty column, instead, we can use the ignore_empty input argument from TEXTSPLIT. Thanks
You can use TEXTBEFORE instead of TEXTSPLIT, as follows: TEXTBEFORE(A2:A4,{"ms","us"})

Rapidminer - Spliting rows that has values in wrong type

I had a data set of 8 millon rows in a txt file with tab delimited format without quotes.
I had 5 of the 14 columns with date values in dd.MM.yyyy format.
Problem 1
I am trying to import the file. In "Format your colums" step, if I choose the type of that colums as "date", it gives errors and all cells in columns turns "?"
So I selected "polynomial" and planed to convert attribute type to date later.
Problem 2 (the real one)
I imported the data and put "nominal to date" operator. When I run I got error in line 14.899:
Cannot parse date: Unparseable date: "0"
I find the line and I see that columns separated wrong. There was a tab character in a string in the a prior cell. So values moved one cell right. And this row was not the only one that moved.
I want to split the rows that has the values in wrong data type for spesified attributes. So I cant correct them manually.
How can I do that in Rapidminer?
Or any other ideas to figure theese problems out?
so most likely you need to adjust the date formatting in this pull-down menu:
To be honest, I usually just import as polynominal and then convert to date in my process. It's easier and reproducable.
You appear to have a broken input file.
The best solution, obviously, is to fix the process that generates the data. Espace or replace tab characters and format the date in a non-ambiguous format such as the ISO date format.
Assuming that you can't fix the date, you should probably write a robust parser program yourself. A generic parser such as rapidminer's won't be able to fix every problem.

Excel: Text String to Date Conversion

I have a working formula for the following text to date conversion. However, I don't understand why the trailing 0 has to be added in order to show the year in YYYY format.
21.04.2016 converts to 4/21/2016
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))+0
It's very simple and straight-forward. However if you remove the 0 at the end of the formula, it will only show 16 instead of 2016. But I could do Right(A2,4) instead of Right(A2,2). But I still like to know why? Anyone? Thanks!
The trailing zero turns the whole thing into a math operation which causes the string (everything to the left of the +0) to be treated as a number.
you could also use *1 instead of +0
=(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))*1
or you could drop the +0 and at the front add -- before the ( and it should all do the same.
=--(MID(A2,4,2)&"/"&LEFT(A2,2)&"/"&RIGHT(A2,2))
As Ed has correctly answered, this is because it is treating your date string as a number.
However, Excel has to interpret the string to get what number it really is, and to do this it relies on regional settings.
Under US regional settings, your formula works great, but when I plug it into excel with UK regional settings I get #Value because "04/21/16" isn't a valid date or number in the UK.
In order to avoid this problem, you should convert it to a date using the DATE() function, which will work irrespective of your regional settings.
=DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2))

Excel IF Date less than a Date not working

I have the following Excel code:
=IF(K4<=31/03/2014,TRUE,FALSE)
K4 contains a date:
01/01/2014
Yes, the code brings back FALSE, I have also tried =IF(K4<="31/03/2014",TRUE,FALSE) but with the same result.
Any ideas or suggestions as to where I am going wrong?
Use
=IF(K4<=DATE(2014,3,31),TRUE,FALSE)
You are testing an inequality with a Float <= String, which returns FALSE. The DATE(,,) fx gives you the required Float for equality comparison.
Alternatively, =K4<=DATE(2014,3,31) is a shorter way of achieving the same.
What K4<=31/03/2014 evaluates to is:
K4 <= (31/03)/2014
31/03 gives 10.333... and that divided by 2014 gives 0.005131... which is why it will always evaluate to false (01/01/2014 is equivalent to 41640, i.e. the number of days since '00/01/1900')
I don't know if it's a system thing, but =IF(K4<="31/03/2014",TRUE,FALSE) gives me TRUE, but then, so does =IF(K4<="31/03/2013",TRUE,FALSE).
A quick and dirty trick would be to multiply the string by 1:
=IF(K4<="31/03/2014"*1,TRUE,FALSE)
The multiplication tells excel to convert the string to a number, if it is parsable (You can also use any other numerical operation that doesn't change the value itself, such as +0).
Note: Excel dates and numbers are the same. Dates are just formatted differently so that a number with a specific format can appear as a date, time, or any other format you can have.
Also, if you really are using this IF construct, you are better of simply using the comparator:
=K4<="31/03/2014"*1
I had the same problem and found that excel was not recognizing one of my 2 columns as a date. (Try changing the date format to 14-Mar-12 to see if this is the case for you)

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Resources