I am fairly new to Knockout and I am looking for way to format the output. I saw an example that was something like this but of course my attempt is not working.
Here is the link to the jsfiddle: http://jsfiddle.net/cezmp/
<div id="VMDiv">
<table>
<thead>
<tr>
<th>Raw</th>
<th>Formatted</th>
</tr>
</thead>
<tbody>
<tr>
<td data-bind="text : SomeData "> </td>
<td data-bind="text : formatPercent(SomeData())"> </td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
function formatPercent(value) {
return value.toFixed(2) + "%";
}
function vm() {
var self = this;
self.SomeData = ko.observable(62.1795972898);
}
ko.applyBindings(new vm(), document.getElementById("VMDiv"));
</script>
You could consider using a computed observable:
If you want a more generic solution you can do something like this
http://jsfiddle.net/5H5AK/
edit: Instead of using true as options, you can supply a object literal with options and use that from the isCurrency extender