Apply dot and decimals to integer in AngularJS - angularjs

I have an integer like 12345. I want to apply a simple filter in AngularJS in order to get two decimal places:
123.45
Update: Thanks to #benohead for the solution:
{{val/100 | number:2}}

All you need is divide 12345 by 100 and then use the number filter to display 2 digits after the comma e.g.:
{{val/100 | number:2}}

Related

SQL query to find any consecutive integer in my amount field

So my data in the table looks like this:
amount | ID
10918.6 | ABC
9999.99 | BCD
9999.89 | DEF
I need to find all consecutive digit (9999.99, 1111.11, 2222.22 etc except 0000.00) So from above example output should give only BCD. I have to check for 1k place only.
If I have 9999.99 and 99.99 it should only give me 9999.99.
Also if I have 989999.99 I have to consider this also as my accepted output
I can do this by using where clause -- column like '%9999.99' or '%1111.11' but I need to find the better way may be by regular exp etc.
Using modulo you can strip away any digits above the 10k position, then check the values are in an accepted list.
WHERE
(amount % 10000) IN (1111.11, 2222.22, 3333.33, 4444.44, 5555.55, 6666.66, 7777.77, 8888.88, 9999.99)
Or...
WHERE
(amount % 10000) / 1111.11 IN (1,2,3,4,5,6,7,8,9)
These avoid turning numbers in to strings, which is generally neither necessary nor prudent.

Google Sheets REGEXEXTRACT from Instagram

I'm facing a particular challenge with regular expression.
I am populating a Google sheet with Google search results of Instagram post captions with the following repetitive pattern:
A | B | C | D
--------------------------------------------------------------------------------
1 | 10.7k Likes, 1.7k Comments - #kristiannairn on Instagram... | |
2 | 4219 Likes, 176 Comments - #djiglobal on Instagram... | |
3 | 1.1m Likes, 209k Comments - #kristiannairn on Instagram... | |
I'm trying unsuccessfully to find the right REGEXEXTRACT formula to extract the number of Likes with decimals and the k/m designators following it and without when it is not existent, to populate Column C, and then the REGEXEXTRACT formula to extract the number of Comments with decimals and the k/m designators following it and without when it is not existent, to populate Column D.
So far I was able to come up with this formula for Column C to extract the Likes:
=REGEXEXTRACT(B1,"(\.?\d*)\W?(?:Likes)")
However, it does not recognize decimals and does not fetch the k/m designators.
I have the same problem with the Column D comments formula I found:
=REGEXEXTRACT(B1,"(\.?\d*)\W?(?:Comments)")
Same here... it does not recognize decimals and does not fetch the k/m designators.
all you need is:
=ARRAYFORMULA(IFNA({
REGEXEXTRACT(B2:B, "(.*) Like"),
REGEXEXTRACT(B2:B, ", (.*) Comm")}))
For Likes, you may use
(\d+(?:\.\d+)?[km]?)\W*Likes\b
and for Comments,
(\d+(?:\.\d+)?[km]?)\W*Comments\b
See the regex demo #1 and regex demo #2. Proof:
Details
(\d+(?:\.\d+)?[km]?) - Group 1: 1+ digits followed with an optional sequence of . and 1+ digits and then an optional k or m
\W* - 0+ non-word chars
Likes - a word Likes
\b - a word boundary.

Display number always with 2 decimal places in <input>

I have a float value for the ng-model that I would like to always display with 2 decimal places in the <input>:
<input ng-model="myNumb" step ="0.01" type="number">
This works for most case when "myNumb" has decimal. But it will not force display of the 2 decimal places if "myNumb" has less than 2 decimal places (3.2), or an integer(30)
How can I force a display of 2 decimal place in the <input> field
AngularJS - Input number with 2 decimal places it could help...
Filtering:
Set the regular expression to validate the input using ng-pattern. Here I want to accept only numbers with a maximum of 2 decimal places and with a dot separator.
<input type="number" name="myDecimal" placeholder="Decimal" ng-model="myDecimal | number : 2" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.01" />
Reading forward this was pointed on the next answer ng-model="myDecimal | number : 2".
If you are using Angular 2 (apparently it also works for Angular 4 too), you can use the following to round to two decimal places{{ exampleNumber | number : '1.2-2' }}, as in:
<ion-input value="{{ exampleNumber | number : '1.2-2' }}"></ion-input>
BREAKDOWN
'1.2-2' means {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}:
A minimum of 1 digit will be shown before decimal point
It will show at least 2 digits after decimal point
But not more than 2 digits
Credit due here and here
{{value | number : fractionSize}}
like {{12.52311 | number : 2}}
so this will print 12.52
Simply use the number pipe like so :
{{ numberValue | number : '.2-2'}}
The pipe above works as follows :
Show at-least 1 integer digit before decimal point, set by default
Show not less 2 integer digits after the decimal point
Show not more than 2 integer digits after the decimal point
Did you try using the filter
<input ng-model='val | number: 2'>
https://docs.angularjs.org/api/ng/filter/number
Another shorthand to (#maudulus's answer) to remove {maxFractionDigits} since it's optional.
You can use {{numberExample | number : '1.2'}}
best way to Round off number to decimal places is that
a=parseFloat(Math.round(numbertobeRound*10^decimalplaces)/10^decimalplaces);
for Example ;
numbertobeRound=58.8965896589;
if you want 58.90
decimalplaces is 2
a=parseFloat(Math.round(58.8965896589*10^2)/10^2);
(Math.round(2.782061* 100 )/100).toFixed(2);
This will convert that into Two decimal places:
For Ex: 2.782061 ---> 2.78 two decimal Places
Use currency filter with empty symbol ($)
{{val | currency:''}}

Angular filter maximum decimals

I want to create a new filter such that i get an input, and i give the amount of maximum decimals to show and return a string that is formatted according to locale.
Input(number) Output for 1 decimal Output for 2 decimals
1.01 1 1.01 / 1,01
1.001 1 1
1.1 1.1 / 1,1 1.1 / 1,1
1 1 1
1000 1 000 / 1.000 / 1,000 1 000 / 1.000 / 1,000
I want to use angular's built in number filter for locale purposes, but i can't come up with how to remove decimals since if i do it after number filter, then i have a locale specific string, and i cant do it before, since i don't know how to round before i have used number:x
Any hints or ideas?
Added my own filter, implemented as such:
app.filter('numberNoDecimalsIfZeroFilter', function($filter) {
return function(value, fractionSize) {
//If has no decimals, then don't show
if(value%1 === 0){
fractionSize = 0;
}
return $filter('number')(value,fractionSize);
}
});
Used as such:
<div class="form-group">
<label class="control-label">Amount: </label>
{{::value.amount | numberNoDecimalsIfZeroFilter}}
</div>
You can't, see filter's implementation:
// format fraction part.
while (fraction.length < fractionSize) {
fraction += '0';
}
The filter always adds zeros. If you want to achieve what you want, you have to write your own filter.

Array formula using multiplication and division across 3 columns

I have Inventory data that is in the following format:
Column D | Column E | Column F
Pack Qty | Pack Price | Total Qty
This is followed by multiple rows with various numerical values, with the odd blank row.
To calculate the stock value of any particular product/line, I use =F2/D2*E2.
To calculate the total value of stock I tried {=Sum(F:F/D:D*E:E)} but it returns a #Div/0! error.
As mentioned, some rows are blank. Some items have 0 price, others have 0 stock on hand.
I would like to avoid having to total each line in a new column then total that column.
Try this:
{=SUM(IFERROR(F:F/D:D*E:E,0))}
You can simply wrap your division inside IFERROR() and return 0.
{=SUM(IFERROR(F:F/D:D,0)*E:E)}

Resources