Skip to content

Instantly share code, notes, and snippets.

@Lunberg88
Last active July 13, 2020 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lunberg88/8af031d426c841e2ca46237663deed60 to your computer and use it in GitHub Desktop.
Save Lunberg88/8af031d426c841e2ca46237663deed60 to your computer and use it in GitHub Desktop.
//**
// src/lang/numeralLocales.js
import numeral from 'numeral';
export const register = (localeName = 'ch', currency) => numeral.register('locale', localeName, {
delimiters: {
thousands: ' ',
decimal: ','
},
abbreviations: {
thousand: 'k',
million: 'm',
billion: 'b',
trillion: 't'
},
ordinal: function (number) {
return '.';
},
currency: {
symbol: currency
}
});
//**
// Hotel.js entity
static afterCreate(model) {
let locale = model.countryCode.toLowerCase();
register(locale, model.propertyCurrency);
numeral.locale(locale);
numeral.defaultFormat('$0,0.00');
}
//**
//
computed: {
totalPrice() {
const booking = Booking.query().first();
return this.$numeral(roundUp((booking && booking.totalPrice) || 0,2)).format();
},
}
//**
// Output: Price total: CHF177,23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment