-
-
Save jwx/2f1344909663c2ab8a14eae9d6f945d8 to your computer and use it in GitHub Desktop.
Decimal converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./two-decimal-value-converter"></require> | |
<h1>${message}</h1> | |
<input value.bind="testing | twoDecimal & updateTrigger:'blur'"/> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { message = 'Hello World'; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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