I am using Freemarker template,I have a decimal value:
a = 23.65
I just want to retrieve above value as:
a = 23.6 <#-- Extract first number after decimal point -->
I have used number_format ex :
<#setting number_format="0.#">
But it rounded off the value after decimal point to 23.7.
Could anybody know how to extract first number after decimal point without rounding off?
You need to use extended formatting option in order to specify a roundingMode.
Please note, that you need at least FreeMarker 2.3.24 for these to work.
By default freemarker uses halfEven rounding mode. For your case, you can try to specify down
${(23.65)?string(",##0.0;; roundingMode=down")}
You can check this expression online here.
Related
I'm trying to make a rounding function in Python to make proper significant figures but I don't know how to remove the quotes from the answer, an ex. is '156.70', I want to have the number with 2 decimal place precision, and
round(156.70,2) returns 156.7.
I have tried this: format(round(156.70,2),'.2f'), but it places the answer in single quotes like I stated above. Is there a way to round directly with the floating point zero, or is there a way to remove the quotes?
I have also tried the strip command which does not remove the quotes.
I also tried converting the answer (156.70) to a numpy array to remove the quotes the following way:
ares1 = np.array(format(round(ans,2),".2f"))
values = ares1.item().split(' ')
ares = np.asarray(values, dtype='float')
Where 'ans' is the value 156.7 I want to round to two precision points. Thanks for any help.
Precision doesn't work in programming as it works in real life. By default, numbers have infinite precision, and any decimal places after the defined decimal places will be zeroes. So, your number 156.7 is the same as 156.70 and 156.7000, as they will all be stored identically in memory.
Now with that out of the way, you can definitely "format" the number when outputting it. That will not edit the actual stored value, but will give you a String representation of the number for display purposes only. For that, I'll refer you to this StackOverflow question.
Howto transform a colum with postive and negative values, which is loaded as text into a column with decial values without errors. the minus sign seems to make the error:
I use a german version of excel 365 on windows 10
Finally solve the problem: It was q quircky minus-sign, which had to be replaced by a standard minus sign before changing type to decimal. Unfortunatley at first sign this quirky decimals looked like nomral ones
In azure logic app I convert kilogram to to pound, I need to round off that result to two decimal numbers.
Expression : mul(float(variables('total_weight')) , 2.20462262185)
Result : 1.102311310925
Expected Result : 1.10
My workaround for rounding the numbers is to use formatNumber() function with fixed-point format. So your code would look like this:
formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2')
The format string in the last parameter - 'F2' - where 2 specifies the decimal places. Two decimal places are the default for the fixed-point format, so you can also just use 'F'.
I can see that you're using it on a property of another object variable, so just like George mentioned you'd need to wrap the result in float() function:
float(formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2'))
For now, there is still no generalized rounding solution in Logic Apps. However you need build solutions specific to your data.
Here is an approach you could round decimals to two for display purpose.
if(contains('56789', substring(string(variables('math')),4,1)),substring(string(add(variables('math'),0.01)),0,4),substring(string(variables('math')),0,4))
This way will return the string format, you could add float() to return float number. I test twice with 2.20462262185 and 2.20562262185.
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
I want to give a pattern in cognos. like this
my number : 12.20
my wanted number : 12.2 i want to delet 0 how I give pattern.
If no data format is mentioned, then the default format will take care of trailing zeros.
But if you are using some data format (number, currency) then the trailing zeros will be added till the mentioned decimal places in your format.
To suppress a digit if the value is zero, you can use pattern attribute in the Data Format property.
In your example, to suppress 2nd decimal place zero, you can mention the pattern as
.0#
With this pattern, first decimal place digit will be shown even if the value is zero. Whereas, second decimal place digit will not be shown even if the value is zero.
Please refer to IBM Cognos inforcenter for Decimal Format Symbols for the Pattern. http://publib.boulder.ibm.com/infocenter/c8bi/v8r4m0/index.jsp