C# Decimal Format 123.123,44 with Rounding - format

I need correct sample of using decimal format and decimal rounding to closest integer.
Sample1: I have number 123.345,51 result need to be 123.346,00
Sample2: I have number 123.345,49 result need to be 123.345,00
I found samples but they all use format with comma first 123,345.00 I need in first place point like 123.345,00
Tried with culture info but did not success ..
Sample code:
var amount = 123.345,77;
var cultureInfo = CultureInfo.GetCultureInfo("da-DK");
var formattedAmount = String.Format(cultureInfo, "{0:C}", amount);
When I need to convert formattedAmount to decimal its breaks... I am converting for Rounding values after ,

Solution is to enable users to input in format they want, like 123123,55 then use .Replace(",", ".") to replace , colon character with dot, after that made Decimal.Round and all problem are solved!

Related

Format percentage to the single digit after the decimal

There is a number like this:
77.18%
It should be displayed like this:
77.2%
I have formatting using:
.4s , .3s, .1% and few other formats which didn't make any change to the format.
Right now the adaptive formatting in Apache superset is giving 2 digits after the decimal, what should be the number format in order to display percentage number with 1 digit after the decimal?
With d3.js, d3.format(".1%")(0.7718) will return 77.2%.
You have to give a decimal number in input to the formatter.

Adding leading Zeros into Day and Month Value

I have a simple table that has a column with a date in this format:
MM/DD/YYYY.
Unfortunately, there are some folks who are working without leading zeros.
Therefore I would like to add a leading zero into the Month and Day element using Power Query to have a common format.
But how? Does someone have any function to share?
Again, not sure why you want to do this, but
Assuming all of the entries are text that looks like dates, you can use the following M-Code:
Split the string on the delimiter
Change each entry in the list to a number
Add 2000 to the last number
Change the numbers back to text with a "00" format
Recombine with the delimiter
let
Source = Excel.CurrentWorkbook(){[Name="Table29"]}[Content],
//set type = Text
#"Changed Type" = Table.TransformColumnTypes(Source,{{"TextDate", type text}}),
xform = Table.TransformColumns(#"Changed Type",
{"TextDate", each
let
x = Text.Split(_,"/"),
y = List.Transform(x,each Number.From(_)),
z = List.ReplaceRange(y,2,1, {2000+y{2}}),
a= List.Transform(z,each Number.ToText(_,"00")),
b = Text.Combine(a,"/")
in b})
in
xform
I am thinking a better solution might be to set up your data entry method so that all dates are entered as dates rather than text

How to convert a decimal field (13.2) to char in power center

How to convert a decimal field (13.2) to char in power center, i have this value in other table 243.00 but the value that return is this 243, i need the follow value 243.00, pls your help
TO_CHAR(field)
There is no straight forward way. Here is a trick you can apply -
SUBSTR(TO_CHAR(col_name+.001),1, length(TO_CHAR(col_name)) )
Please validate it before applying.

Freemarker displays int value as double value(e.g. prints 0 as 0.00)

I am trying to write a freemarker template file having information about a table.
I have written '${noRows}' in the template for table rows count.
The noRows is a int value:
int noOfRows = myTable.getNumRows();
data.put("noRows", noOfRows);
The noOfRows is always an integer value but in the output file it is displayed as double value with ".00" appended to it.
How can I display the value as integer only.
If the value is indeed an integer, all you should need to do is
${noOfRows?string}
You can also use the Java decimal number format syntax:
${noOfRow?string["0"]}
Reference: http://freemarker.org/docs/ref_builtins_number.html#ref_builtin_string_for_number
Apparently, your number_format setting is set to 0.00 or like. (FreeMarker doesn't care about Integer VS Double when formatting numbers. It just have a single numerical type, and it formats all of them according to that setting.) Check it wherever FreeMarker is configured. As last resort, you can also set this setting in the template like <#setting number_format="0.##">. Last not least, as "sev" said, you can specify the format at each place individually.

Cannot cast object '(10)' with class 'java.lang.String' to class 'java.lang.Integer'

I am using ireport 3.7.1. I have made a connection with my database.I have a procedure which when given an input in number ,it returns the word format of the number i.e if I give input 10,it will return ten. The problem is when I am executing the procedure in pl/sql developer,I am getting the proper output but when I am firing the same procedure in ireport it's giving me this exception
Cannot cast object '(10)' with class 'java.lang.String' to class 'java.lang.Integer' .
Casting straight from a String to an Integer is not possible. You'll want to use the function Integer.parseInt(stringNumber);
(10) isn't a properly formated integer. Not even for PL/SQL:
select '(10)' +0 from dual;
> ORA-01722: invalid number
I could only suggest you to trace back the point where those ( ) come from. And fix your code at that position instead. Just a wild guess, some number formats use parenthesis to represent negative numbers. Maybe this is your case?
That being said, if you still want to locally remove the parenthesis that have somehow lurked inside of your string:
String str = "(10)";
int value = Integer.parseInt(str.substring(1, str.length()-1));
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// *blindly* get away of first and last character
// assuming those are `(` and `)`
For something a little bit more robust, and assuming parenthesis denotes negative numbers, you should try some regex:
String str = "(10)";
str = str.replaceFirst("\\(([0-9]+)\\)", "-$1");
// ^^^ ^^^ ^
// replace integer between parenthesis by its negative value
// i.e.: "(10)" become "-10" (as a *string*)
int value = Integer.parseInt(str);

Resources