django thousand separator for product price in templates - django

i have the product price in decimals,
like 15000.0000
now i want to apply thousand separator on it, intcomma filter works fine with decimals as here
but after it i can't apply currency filter, means it didn't work with currency filter.
i want final output of my Price: PKR 15,000.00
any suggestions to get this?
Thanks :)

The satchmo currency filter requires something that can be converted into a Decimal. However intcomma returns a string, and since it adds the thousand separators, it can no longer be converted to a Decimal.
The solution would be to write a currency_with_intcomma template filter yourself, which first runs through the currency filter and then applies the thousand separators (you can't use the builtin filter for that, you'll have to do it "manullay").

Related

Azure data factory - mapping data flows regex implementation to format a number

I am creating a mapping data flow where I have a phone number column which can contain values like
(555) 555-1234 or
(555)555-1234 or
555555-1234
I want to extract numbers from this value. How can that be done. I have tried the below function with different variations but nothing is working.
regexExtract("(555) 555-1234",'\d+)')
regexExtract("(555) 555-1234",'(\d\d\d\d\d\d\d\d\d\d)')
Because you have multiple phone formats, you need to remove parentheses and spaces and dashes so you need multiple statements of regexExtract which will make your solution complicated.
instead, i suggest that you use regexReplace, mainly keeping only digits.
i tried it in ADF and it worked, for the sake of the demo, i added a derived column phoneNumber with a value: (555) 555-1234
in the derived column activity i added a new column 'validPhoneNumber' with a regexReplace value like so:
regexReplace(phoneNumber,'[^0-9]', '')
Output:
You can read about it here: https://learn.microsoft.com/en-us/azure/data-factory/data-flow-expressions-usage#regexReplace

do a format for only one row?

I have this measure in DAX:
SWITCH ( TRUE () ,
MIN ( 'Dynam'[ID] ) = 5 , DIVIDE ( [Gross] , [Revenue] ) * 100,
MIN ( 'Dynam'[ID] ) = 8 , [Hours]
)
I would like the first one to have one decimal, but not the second one.
Can I do a formatting for one row only?
As of now, I have it like this for the entire measure:
Here are a few options:
Like Jeroen said, you can use FORMAT in your measure but it will be text. If you can't have the measure as text is some places, just have a text measure and a number measure.
Use two measures, one for hours and one for dollars. You can't really chart or SUM things well when sometimes it's hours and sometimes it's dollars, so split them out.
You could always drop the decimals on the dollars and use whole number for both.
If your data for both is always positive, you can play tricks with the positive and negative formats in Power BI (and probably SSAS?) using a custom format string such as 0.00;0;0. In a custom format string, the first format is the positive number, the second is negative, and the last is zero. The trick is to use the positive format for dollars and the negative format for hours. Here, positive numbers are shown with decimals (0.00), negative numbers are shown as whole numbers without a minus sign so that they look like positive numbers (0):

How do I create a custom format in Django for the following: YYYY-NNNN, where YYYY represents the year and NNNN represents a 4 digit numeric value

I been trying to find ways to create a custom format for a value input for a model. I can't seem to find the adequate way to create a a year then 4 digit number after the slash.
I would really appreciate if you could help.

Arrayformula not working for Google Spreadsheet settings having locale other than US

I have created a Google spreadsheet with Locale set to Brazil and Timezone set to (GMT-03:00) Sau Paulo that has a Date column having dates in their regional format like 01-jan.-2021, 23-fev.-2021 etc.
I have created a Month column next to this Date column and trying to populate the months using Arrayformula:
=ARRAYFORMULA(IF(LEN(F2:F),MONTH(F2:F),))
It doesn't seem to work if i use IF or LEN in the Arrayformula function, however, seems to work if i simply do this:
=ARRAYFORMULA(MONTH(F2:F))
which obviously fills down all rows including blank date cells and adds more rows.
Another thing i noted is, if i change the Spreadsheet settings to Locale : United States & Timezone : Eastern Time (GMT-04:00), the Arrayformula with both the IF & LEN functions seems to work! However, it doesn't work for the above region.
If anyone has an alternative solution to make it work, please do share here!
In a Google Spreadsheet, the arguments in any given function are separated either by a decimal point OR a decimal comma. The applicable separator depends on the spreadsheet locale (File, Spreadsheet settings, Locale) and the decimal separator used by that country
If the locale is a country that uses a decimal point (.) as a decimal separator, then function arguments are typically separated by use a comma (,).
If the locale is a country that uses a decimal comma (,) as a decimal separator, then function arguments are typically separated by use a semi-colon (;).
Brazil uses a decimal comma, so Google Sheet arguments are separated by a semi-colon.
=ARRAYFORMULA(IF(LEN(F2:F),MONTH(F2:F),)): FAIL
=ARRAYFORMULA(IF(LEN(F2:F);MONTH(F2:F);)): SUCCESS
United States uses a decimal point), so Google Sheets should be separated by a comma.
=ARRAYFORMULA(IF(LEN(F2:F),MONTH(F2:F),)): SUCCESS
=ARRAYFORMULA(IF(LEN(F2:F),MONTH(F2:F),)): FAIL
The snapshots below are taken from two spreadsheets (#1 locale=Brazil, #2 Locale=USA) and demonstrate the application of a comma or a semi-colon as a argument separator.
Brazil
USA

How to add comma thousand separator shows error if number has ".00"

How to add comma thousand separator in Power BI [Query Editor]
The above post was great. However when I have a number (to 2 decimal places) that ends in .00 it returns an error. For other numbers it works brilliantly.
What do I need to adjust so the numbers ending in ".00" work?
I've worked out it is in this line:
{numberAsTextList = Text.Split(Number.ToText(Number.Abs(n), null, "en-US"), ".")}
I actually negated the need for a 'function', by just creating a new custom column using:
Number.ToText([put your reference column here],"N")
Funny thing is even the Microsoft site on Number.ToText doesn't give the "N" as an example. I managed to find it at
https://excelinexcel.in/ms-excel/powerquery-m/number-totext-function/