Angular 7: Get locale thousand Separator and decimal Marker characters - angular7

I've seen solutions where people are writing out amounts with formatCurrency(1234.56, this.locale, '') and then extracting the characters from the produced string.
Please Google ... tell me this is not the only way.

thousand Separator:
getLocaleNumberSymbol(this.locale, NumberSymbol.CurrencyGroup)
decimal marker:
getLocaleNumberSymbol(this.locale, NumberSymbol.CurrencyDecimal)

Related

How to convert a formatted string into plain text

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"

Extracting numbers with REGEXEXTRACT that might have a comma or dot

I have a list of numbers in a few formats that may or may not include a dot and a comma. The numbers are locked in a string. For example:
hello 1,000 goodbye
hola 2,000.12 ciao
Hallo 3000.00 Auf Wiedersehen
How can I extract the numbers?
I don't care if the comma is added but the dot is obviously important.
I need the regular_expression to be used in REGEXEXTRACT (and the rest of the REGEX formulas.
The output should be:
1000
2000.12
3000.00
Supposing that your raw data is in A2:A, use this in B2 (or the second cell) of an otherwise empty column:
=ArrayFormula(IF(A2:A="",,IFERROR(VALUE(REGEXEXTRACT(A2:A,"\d[\d,\.]*\d")))))
The REGEX portion reads, in plain English, "Extract any portion that starts with a digit followed by any number of digits, commas or periods (or none of these) and ends with a digit."
You will likely want to apply Format > Number > Currency to the results column.

Regex and decimal.TryParse are not working to test for decimals

It is late. I am a beginner with C# and have been to six different websites and cannot find the answer to this question. I am trying to test for decimals to make sure the user enters one and not some other character. All of the solutions out there involve string and decimal. How do I just test for decimal. I am not converting a string to a decimal. The below methods worked for testing for strings. Using 4 backslashes did not work either. decimal.TryParse is not working as well. Can someone please offer insight. Thanks.
error 1 Regex: Cannot convert from decimal to string
error 2 TryParse: Cannot convert from decimal to System.ReadOnlySpan
Console.WriteLine("Please enter a number");
decimal enteredNumber1 = decimal.Parse(Console.ReadLine());
if (!Regex.IsMatch(enteredNumber1,"^[0-9]\\\\d{0,9}(\\\\.\\\\d{1,3})?%?$"))
{
Console.WriteLine("Numbers only");
}
if (!decimal.TryParse(enteredNumber1, out enteredNumber1))
Console.WriteLine("Numbers only");

Currency format is excelJS

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?

Prawn PDF number_with_delimiter number_to_currency? [duplicate]

As you can see from the title, I would like to write a regular expression pattern to find a string that consists of various numbers and is separated by comma every three digits. The length of string can vary.
I am still pretty new to regular expression thingy so can anyone help me with that? Thanks a lot in advance.
P.S.
Anyone could also suggest some of good resources, like website, books, etc, for learning regular expression?
This regex shall match that:
\d{1,3}(?:,\d{3})*
If you want to exclude match to a substring of an ill-formed pattern, you might want to do:
(?:\A|[^,\d])(\d{1,3}(?:,\d{3})*)(?:\z|[^,\d])
Explanation of the first regex
\d{1,3} 1 to 3 consecutive numerals
,\d{3} A comma followed by 3 consecutive numerals
(?:,\d{3})* Zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
Explanation of the second regex
(?:\A|[^,\d]) A non-capturing group of either the beginning of the string, or anything other than comma or numeral
(\d{1,3}(?:,\d{3})*) A capturing group of 1 to 3 consecutive numerals followed by zero or more repetition of a non-capturing group of a comma followed by 3 consecutive numerals
(?:\z|[^,\d]) A non-capturing group of either the end of the string, or anything other than comma of numeral
Try http://regexlib.com for good examples and links to tools to help you get up to speed with RegEx
Also try this regex tester app http://www.ultrapico.com/Expresso.htm
And another tool I've used before here http://osherove.com/tools

Resources