How to convert string to double in angular - html

I am using a payments API in my application and am getting the invoice value with type number
signature.invoice.amount: 10500 (Number)
I tried to use currency pipe {{ signature.invoice.amount | currency: 'BRL': true}} and the transformed value is: $ 10,500.00.
But the transformed value should be $ 105.00 ... how do I get the number of the amount received to a monetary value in 'BRL' with a return of the number type?

Since $105.00 is 10,500 cents, you want to convert it to dollars before transforming it:
{{ signature.invoice.amount / 100 | currency: 'BRL': true}}
Good job storing currency as cents though! That's the way to do it to save yourself errors down the line.

Related

Count Array Length in JSON Message Object with Amazon Cloudwatch Logs Insights

Is there any way to get the length of an array found in a JSON object parsed by cloud watch log insights?
For example, when sending a JSON object of the following structure to log insights:
{
names: ['john', 'doe', 'joe', 'schmoe']
}
it gets parsed into the following fields:
names.0: john
names.1: doe
names.2: joe
names.3: schmoe
and can be accessed by
fields #timestamp, names.0, names.1, ...
In this example, is there a way to get a field called number_of_names?
e.g., | parse get_length(names) as number_of_names
Here is an ugly workaround for smaller arrays where the max length is known:
fields #timestamp, ispresent(names.0) + ispresent(names.1) + ispresent(names.2) + ... + ispresent(names.10) as names_length

Use Google APIs to calculate the timezones of each location object and then return output as this same array of objects

1) a) You have a list of addresses. Use Google APIs to calculate the timezones of each location object and then return output as this same array of objects, with each object comprising of following values -
[{
"id":"1",
"address":"Plot 5, CDCL Building, Chandigarh"m
"latitude":"30.123123",
"longitude":"76.123213"
"timezone":"-330", //in minutes
"UTC_time":"2016-10-18 5:30:00 AM"
}]
b) Now write an algorithm, to divide this array into least no. of sub-arrays, such that difference between the minimum UTC_time and maximum UTC_time in that array is less than or equal to 4 hrs.
2) Parse the attached html file and generate a JSON file as output, which contains all the key
FORMAT
Test Duration- 5 Hours
Test Date -27 October,2016
Format to be send in : "Student name- college name -roll number- 2016"||
Email Id - kunal#tookanapp.com ( All the students need to send their test on the mentioned email ID in the mentioned format )
Start Time - 11.00 AM
End Time - 4.00 PM
Just go through this link.You will get the answer.
https://developers.google.com/maps/documentation/timezone/intro
This is an algorithm not a program::--
initialise i, ar [100],d ;
MAX UTC_time= +14:00(150°);
Min UTC_time=-12:00 (180°);
for min UTC_time initialise to -12:00;
min UTC_time <=+14:00
If min UTC_time > +10:00
Then d=max UTC _time - min UTC_time;
And then print d;
Else
Min UTC_time++;
Link is :--
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&key=YOUR_API_KEY
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
In html language......
OK
-28800.0000000
0.0000000
America/Los_Angeles
Pacific Standard Time
time_zone_name>

String concatenation of key in map with variable in angularjs

So I have this angularjs code in my html where I am trying to access the value of a key/value pair like so:
<td>{{ mapA.[stringX. + mapB.keyC + .stringY]}}</td>
The value of mapB.keyC should concatenated to the String key to get the value of a particular key/value pair, so that the name of the key for example would be something like stringX.valueC.stringY to return the value of the map
How would I do this in angularjs and/or in pure javascript?
EDIT:
I tried to be general, however in my case I have a credit meter with a particular local currency as within its name e.g. "credit.in.cash.GBP.2000" and I want to get the value of it with:
{{ meter.[credit.in.cash. + localCurrency.ISO_CODE + .2000] / 100 | currency : localCurrency.SYMBOL : 2 }}
expected e.g. £2000

Jira JSON date format

I am using the Jira API, and need the start and end dates for a sprint.
The JSON data I get back is :
{"jodaTimeZoneId":"Europe/Berlin","sprints":[{"id":5,"start":"13082015044305","end":"27082015044305",...
Normally, json returns the date in milliseconds, and you need to deserialize that.
Now however, I can clearly see the date (13-08-2015 & 27-08-2015) followed by some other numbers I don't care about. Is there anyway Angular can get the correct format using | date? Or any other way I can use?
When I use {{13082015044305 | date:'dd-MM-yyyy'}} it returns 21-07-2384. The parsing date format is wrong. So change the format to recognized way.
So I used
input.toString().replace(/(\d\d)(\d\d)(\d\d\d\d)(\d\d\d\d\d\d)/, '$1-$2-$3');
Used it in a custom filter.
app.filter('correctDateFormat', function() {
return function(input) {
return input.toString().replace(/(\d\d)(\d\d)(\d\d\d\d)(\d\d\d\d\d\d)/, '$1-$2-$3');
};
});
Then
Display the date as
{{13082015044305 | correctDateFormat }}
I think you can use
{{ data | filter:options }}
where data is your json and date filter
{{'1388123412323' | date:'MM/dd/yyyy # h:mma'}}
an option like this.

jinja format strings that could be "None"

I'm getting started with Jinja by converting my Django templates. Let's say I have a variable that represents a dollar value. So if I want to format it to two decimal places, I would do this:
{{"%.2f" | format(my_dollar_var)}}
But what if my_dollar_var is None? In that case, I'd like to show something else (like a question mark or a dash -- but not a zero).
I use a customer Currency filter:
def Currency(value):
if(value == None):
return "???"
else:
return "${:,.2f}".format(float(value))
jinja2.filters.FILTERS['Currency'] = Currency
Then just use:
{{ PRICE | Currency }}
Hope this helps!