How do you format currency in exceljs?
All I've found is this from their docs...which I have no clue how to type so I pasted it, but it doesn't seem to work
// Set Column 3 to Currency Format
ws.getColumn(3).numFmt = 'οΏ½#,##0;[Red]-οΏ½#,##0';
Just took a little bit of tinkering with.
ws.getColumn(3).numFmt = '$#,##0.00;[Red]-$#,##0.00';
The #'s are optional digits. If you don't care about negative numbers being red you can leave it as $#,##0.00
For the full Accounting format, eg left-justified '$', $- for $0.00, etc, you can use:
const numFmtStr = '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(#_)';
cell.numFmt = numFmtStr;
see: What are .NumberFormat Options In Excel VBA?
Related
User copy paste and send data in following format: "ππ π§πͺ ππππππ"
I need to convert it into plain txt (we can say ascii chars) like 'jovy debbie'
It comes in different font and format:
ex:
'π±πππππ π«ππππ'
'πΆππππππ’π π½πππππ π»πππππ'
Any Help will be Appreciated, I already refer other stack overflow question but no luck :(
Those letters are from the Mathematical Alphanumeric Symbols block.
Since they have a fixed offset to their ASCII counterparts, you could use tr to map them, e.g.:
"ππ π§πͺ ππππππ".tr("π-π«", "a-z")
#=> "jovy debbie"
The same approach can be used for the other styles, e.g.
"π±πππππ π«ππππ".tr("π-ππ¨-π", "a-zA-Z")
#=> "Jenica Dugos"
This gives you full control over the character mapping.
Alternatively, you could try Unicode normalization. The NFKC / NFKD forms should remove most formatting and seem to work for your examples:
"ππ π§πͺ ππππππ".unicode_normalize(:nfkc)
#=> "jovy debbie"
"π±πππππ π«ππππ".unicode_normalize(:nfkc)
#=> "Jenica Dugos"
I couldn't really clarify what I'm asking in the title. I an integer for a day and a month. I have to print the month with a 0 in front of it if it's one digit only.
For example 04 if month = 4 and so on.
This is how it's supposed to look like in C#:
Console.WriteLine("{0}.{1:00}", day, month);
Thank you.
int month = 4;
DecimalFormat formater = new DecimalFormat("00");
String month_formated = formater.format(month);
Besides the answer Fernando Lahoz provided (which is pretty specific to your case: decimal formating) you can also use System.out.format in Java which allows you to specify a format-string while printing to System.out (the format function is applicable to any PrintStream though). In your case
System.out.format("%2d %2d", day, month)
should do the trick. The %dis used for decimal integers and you can then specify any width you want just before the 'd' (2 in your case).
If you want to access the string formed for later use and not (only) print it you can use String.format. It uses the same format as System.out.format but returns the String that is formed.
A complete syntax for all formats(string, decimal, floating point, calendar, date/time, ...) can be found here.
If you'd like a quick tuto on number-formatting you can check this link or this link instead.
Good luck!
I am trying to convert the type of string to long in the following code:
PaymentReceived = String.Format(new CultureInfo("en-IN", true), "{0:n}", t.PaymentReceived),
Here t.PaymentReceived is of type long, and the PaymentReceived is of type string but I want it to be of type long.
I am using this to convert the PaymentReceived value into comma separated value.
I am trying to do as of my knowledge like
PaymentReceived = Convert.ToInt64( String.Format(new CultureInfo("en-IN", true), "{0:n}", t.PaymentReceived))
But the error is Additional information: Input string was not in a correct format.
So please help me with another solution, thank you.
The formatter n, adds additional non-numeric characters. For en-IN culture, that means a number like 1000 ends up as 1,000.00.
The Convert.ToInt64 method requires that the string be 100% numeric, including no period, which might be fine for Convert.ToDecimal, but a long is not a float. Therefore, emphatically, your string is not formatted correctly, and the error is both obvious and correct. I'm not sure what your ultimate goal here is, but it makes no sense to convert a long to a formatted string and then immediately convert it back to a long, anyways.
Assuming you have only the string and you need to format it as a long, then you need to ensure that it's formatted as a long should be. That requires:
Split on the decimal point and take just the left side:
str = str.Split(new[] { '.' })[0];
Replace any commas with empty strings:
str = str.Replace(",", "");
That assumes you know the format will something like 1,000.00. Otherwise, you may want to use a regex to replace all non-numeric characters with an empty string, instead. However, you still need to split on the decimal. Otherwise, if you just removed all non-numeric characters from something like 1,000.00, then you'd end up with 100000, a number 100 times larger than the actual string number. Also, this is all dependent on the culture. Some cultures use , as the decimal separator and . and delimiter in large numbers. If you need to handle various cultures, you'll need to adjust accordingly.
I have a date of this type: 2004-12-31 23:00:00-08 but no one of the patterns i know and i have used from the documentation is working. I thought it should something like "yyyy-MM-dd HH:mm:ssX" but it isn't working.
Sorry for you, but this is a known bug and was already reported in January 2014. According to the bug log a possible solution is deferred.
A simple workaround avoiding alternative external libraries is text preprocessing. That means: Before you parse the text you just append the prefix ":00". Example:
String input = "2004-12-31 23:00:00-08";
String zero = ":00";
if (input.charAt(input.length() - 3) == ':') {
zero = "";
}
ZonedDateTime zdt =
ZonedDateTime.parse(
input + zero,
DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ssXXX"));
System.out.println(zdt);
// output: 2004-12-31T23:00-08:00
UPDATE due to debate with #Seelenvirtuose:
As long as you ONLY have offsets with just hours but without minute part then the pattern "uuuu-MM-dd HH:mm:ssX" will solve your problem, too (as #Seelenvirtuose has correctly stated in his comment).
But if you have to process a list of various strings with mixed offsets like "-08", "Z" or "+05:30" (latter is India standard time) then you should usually apply the pattern containing three XXX. But this currently fails (have verified it by testing in last version of Java-8). So in this case you still have to do text preprocessing and/or text analysis.
Any way to convert Float to string with out getting E (exponent).
String str = String.valueOf(floatvalue);
txtbox.settext(str);
and i am using NumericTextFilter.ALLOW_DECIMAL in my textField which allow decimal but not E.
i am getting like this 1.3453E7 but i want it something like 1.34538945213 due to e i am not able to set my value in edit text.
so any way to get value with out e.
I'm not 100% sure I understand what number you're trying to format. In the US (my locale), the number 1.3453E7 is not equal to the number 1.34538945213. I thought that even in locales that used the period, or full stop (.) to group large numbers, you wouldn't have 1.34538945213. So, I'm guessing what you want here.
If you just want to show float numbers without the E, then you can use the Formatter class. It does not, however, have all the same methods on BlackBerry that you might expect on other platforms.
You can try this:
float floatValue = 1.3453E7f;
Formatter f = new Formatter();
String str = f.formatNumber(floatValue, 1);
text.setText(str);
Which will show
13453000.0
The 1 method parameter above indicates the number of decimal places to show, and can be anything from 1 to 15. It can't be zero, but if you wanted to display a number without any decimal places, I would assume you would be using an int or a long for that.
If I have misunderstood your problem, please post a little more description as to what you need.
I'll also mention this utility class that apparently can be used to do more numeric formatting on BlackBerry, although I haven't tried it myself.
Try this:
Double floatValue = 1.34538945213;
Formatter f = new Formatter();
String result = f.format("%.11f", floatValue);
Due to the floating point presentation in java, the float value 1.34538945213 has not the same representation as the double value 1.34538945213. So, if you want to get 1.34538945213 as output, you should use a double value and format it as shown in the example.