1.

How To Convert Currency In Aurelia?

Answer»

Convert Currency :This is an example of currency FORMATTING. You will notice that the concept is the same as in above example. First we need to install numeral LIBRARY from command prompt.

C:UsersusernameDesktopaureliaApp>jspm install numeral

Converter will set currency FORMAT.

converters.js

IMPORT numeral from 'numeral';

export class CurrencyFormatValueConverter
{
toView(value)
{
return numeral(value).format('($0,0.00)');
}
}

View-model will just generate random number. We will use this as currency value and update it every second.

app.js

export class App
{
constructor()
{
this.update();
setInterval(() => this.update(), 1000);
}
update()
{
this.myCurrency = Math.random() * 1000;
}
}

Our view will show the randomly generated number transformed as a currency.

app.html

 ${myCurrency | currencyFormat}

 

Convert Currency :This is an example of currency formatting. You will notice that the concept is the same as in above example. First we need to install numeral library from command prompt.

C:UsersusernameDesktopaureliaApp>jspm install numeral

Converter will set currency format.

converters.js

import numeral from 'numeral';

export class CurrencyFormatValueConverter
{
toView(value)
{
return numeral(value).format('($0,0.00)');
}
}

View-model will just generate random number. We will use this as currency value and update it every second.

app.js

export class App
{
constructor()
{
this.update();
setInterval(() => this.update(), 1000);
}
update()
{
this.myCurrency = Math.random() * 1000;
}
}

Our view will show the randomly generated number transformed as a currency.

app.html

 ${myCurrency | currencyFormat}

 



Discussion

No Comment Found