integer digit grouping in grails scaffolded views - grails

I have a default scaffolded view and in the list view, all my integer values are shown with digit grouping. (like 5,129)
I couldn't find a way to disable this behavior. I tried on both English and Turkish locale. I am not sure if it is used but the messages.properties file is all default values:
default.date.format=yyyy-MM-dd HH:mm:ss z
default.number.format=0
If I change the view and add g:formatNumber around the value such as
<g:formatNumber number="${fieldValue(bean: tagInstance, field: 'tag_id')}" type="number" groupingUsed="false" />
all that gets printed is 5 (for the number 5129)

Eliminating the fieldValue() call fixed it.
${tagInstance.tag_id}
prints the number without any formatting.

Have you tried this:
default.number.format=#
Note that the # will cause a value of 0 to not display. If you want it to display, you'll probably want:
default.number.format=#0

Related

How do you convert text like `'$71.4145` into a number you can do arithmetic with

The title says it all. One thing I want to avoid is long formulas. If it's more than a single function, something is clearly wrong since this should be a common use case.
I've tried TO_PURE_NUMBER and VALUE
Your question suggests that the value $71.4145 is not a number but a text string. That can happen if your spreadsheet locale is such that it expects comma as decimal mark, or expects a different currency symbol. It will also happen if you have formatted the value as plain text rather than currency.
To convert the text string $71.4145 into the number 71.4145 (seventy-one and change), use regexextract(), like this:
=iferror( value( regexextract( to_text(A2), "[\d.]+" ) ) )
Just use -- to suppress text to equivalent number values. Try-
=--A1
try:
=SUBSTITUTE(A1; "$"; )*1

GoogleFinance - Remove USD Symbol

Using google spreadsheets to display currency data, with USD as primary field for formula: =LEFT(V10*GoogleFinance("currency:USDEUR"),5)
I cannot figure out how to remove the the USD Symbol ($) from not show up for the additional currencies. It makes no sense to have the **$**xxx being displayed on non-USD data.
I have tried doing Format -> Numbers but none of those options resolve this issue.
The number formats are not working since the LEFT function is converting the value to text. Does this formula work instead:
=SUBSTITUTE(LEFT(V10*GoogleFinance("currency:USDEUR"),5),"$","")
Highlight the cells you want to change. Go to Format --> Number --> More Formats --> Custom number format. Highlight the "$" and delete it (delete the quotes and dollar sign both). Click apply. I have attached before and after pictures.

Split function treating dashes oddly

Why does =SPLIT("1,2-5,4", ",")
equal
1 42040 4
instead of
1 2-5 4 ?
I have all of the cells formatted at plain text.
Regextract should give you the desired output. Try:
=ArrayFormula(regexextract("1,2-5,4", {"^(\d+),",",(.+),",",(\d+)$"}))
To complement JPV's answer.
You can use:
=REGEXEXTRACT(A1,"(.*?),(.*?),(.*)")
which is "hard-coded" to splitting exactly 3 elements (as JPV's is). To give more flexibility, you can use something like:
=REGEXEXTRACT(A1&REPT(",",10),REPT("(.*?),",10))
which is limited to a maximum of 10 elements (that number can be changed to suit). However, it will output an array that is always that maximum number of elements long (padded out with blank cells). You could use QUERY or FILTER to filter out those blank cells - the formula will become a little convoluted.
Alternatively, you can "code" your string such that automatic date coercion is avoided, and then "uncode" it after the SPLIT:
=ArrayFormula(SUBSTITUTE(SPLIT(SUBSTITUTE(A1,"-","x"),","),"x","-"))
With 1,2-5,4 in a cell this can be split as required with Data > Split text into columns... .

Showing float numbers Grails in gsp

I want to manipulate float numbers in gsp, here is what i want:
If the number has a 1.* i want it to show the dot, but if it ends with zero i dont want it to show the dot and zero.
like this:
Score: 1.5
Score: 1
Score: 2.1
Score: 3
The score variable is a float number and it is an input field on the gsp that loads the number and it can be changed.
But the real problem is, how can i see if the number has decimals?
There is already a taglib for formating numbers: (g:formatNumber)
I think something like this should work:
<g:formatNumber number="${score}" type="number" format="###.##"/>
But...if that doesn't work...
I would say write your own custom taglib. If it is something that is going to be used multiple times, why loop through a list of objects in your controller, change the float to a string just to display it? Let the page decide how to show it in the proper context.
Or
Add a transient field to the domain object (String scoreDisplay) and then have getScoreDisplay() return the value of score as a string, formatted how you want.
Well, I'd suggest you to format the number in your controller - before it gets to your gsp. That way you have more control over the number format. Once you're in the gsp, you have to use a grails' decimal number format or make your own taglib to format (since the number of fractional digits changes in your case).

Reportviewer regular expression check

In my report viewer i have a table displaying data in different columns. I wanted to have a regular expression to check the content in a textbox of a table to see if it is NULL to place a 0 in the textbox. Currently if there is returned data it is displayed and if not then there is empty space which i would like to replace it with a 0
here is what i had for a regular expression for the textbox:
=IIf(Fields!FirstAmount.Value = " ","0",Fields!FirstAmount.Value)
Any ideas or other ways to resolve this issue.
I resolved my issue using the following expression:
=IIF(Fields!FirstAmount.Value Is Nothing, "0", Fields!FirstAmount.Value)
depending if the First Amount field is null or not it will be replaced by 0 if it is empty and if not it will show its data.

Resources