javascript - Align decimal points to right in input type text -
i want format numbers 2 decimal places , want aligned the, i.e. don't want numbers centered, left aligned, etc. don't know how easy do, want alignment on decimal point.kind of this:
123.44 1465.23 12.24
right align ok long numbers have 2 dp. don't want numbers this:
1554 23.75
they should this:
1554.00 23.75
html code
<table class="table grey-table"> <thead> <tr> <th style="padding:1px 8px;">description</th> <th style="padding:1px 8px;">total</th> </tr> </thead> <tr> <td style="padding:1px 8px;">countertops</td> <td style="width:150px;"><input type="text" id="txt_cm_countertops" readonly="true" style="width:150px;"/></td> </tr> <tr> <td style="padding:1px 8px;">li in.</td> <td style="width:150px;"><input type="text" id="txt_cm_countertops_lf" readonly="true" style="width:150px;"/></td> </tr> <tr> <td style="padding:1px 8px;">bowls</td> <td style="width:150px;"><input type="text" id="txt_cm_bowls" readonly="true" style="width:150px;"/></td> </tr> <tr> <td style="padding:1px 8px;">side splashes</td> <td style="width:150px;"><input type="text" id="txt_cm_sidesplashes" readonly="true" style="width:150px;"/></td> </tr> <tr> <td style="padding:1px 8px;">subtops</td> <td style="width:150px;"><input type="text" id="txt_cm_subtops" readonly="true" style="width:150px;"/></td> </tr> </table> <sript> var = 24; //these values demo. these not hardcorded var j = 15.5; var k = 4; var l = 4; var m = 21.4; $("#txt_cm_countertops").val(i); $("#txt_cm_countertops_lf").val(j); $("#txt_cm_bowls").val(k); $("#txt_cm_sidesplashes").val(l); $("#txt_cm_subtops").val(m); </script>
this image of above table want align total column having
you have use css text-align: right attribute , javascript mask.
this jquery plugin 1 i've had luck with:
http://digitalbush.com/projects/masked-input-plugin/
example:
<script src="jquery.js" type="text/javascript"></script> <script src="jquery.maskedinput.js" type="text/javascript"></script> <script> $( document ).ready(function() { // find field id of 'mynum' , mask display 2 digit number $("#mynum").mask("9.99"); // add mask of 2 digit number class of 'twodigit' $(".twodigit").mask("9.99"); // old browsers don't class method have run for/each // loop class name $(".twodigit").each(function(){ $(this).mask("9.99"); }); }); </script>
Comments
Post a Comment