Skip to content

Instantly share code, notes, and snippets.

@jwx
Forked from plwalters/app.html
Last active June 12, 2017 23:01
Show Gist options
  • Save jwx/2f1344909663c2ab8a14eae9d6f945d8 to your computer and use it in GitHub Desktop.
Save jwx/2f1344909663c2ab8a14eae9d6f945d8 to your computer and use it in GitHub Desktop.
Decimal converter
<template>
<require from="./two-decimal-value-converter"></require>
<h1>${message}</h1>
<input value.bind="testing | twoDecimal & updateTrigger:'blur'"/>
</template>
export class App { message = 'Hello World'; }
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export class TwoDecimalValueConverter {
toView(value) {
if(typeof value === 'number') {
return value.toFixed(2);
}
return value;
}
fromView(value) {
if (typeof value !== 'string') {
return value;
}
var num = Number(value);
if (isNaN(num)) {
return null;
}
if (value.indexOf('.') > -1) {
return num;
}
if (num >= 100) num /= 100;
return num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment