Basic number formatting
The number method takes up to four parameters, but only the first one is required.
1.Number: The number you want to format.
$.number( 5020.2364 ); // Outputs 5,020
2.Decimal Places: The number of decimal places you wish to see. Defaults to 0.
$.number( 5020.2364, 2 ); // Outputs: 5,020.24
3.Decimal Separator: The character(s) to use as a decimal separator. Defaults to '.'.
$.number( 135.8729, 3, ',' ); // Outputs: 135,873
4.Thousands Separator: The character(s) to use as a thousands separator. Defaults to ','.
$.number( 5020.2364, 1, ',', ' ' ); // Outputs: 5 020,2
Number formatting as-you-type
When targeting a collection of input elements, you can have the number format plugin automatically format the users input based on your format settings.
$('input.number').number( true, 2 );
Passing true to the number parameter, indicates that you want the value of the field or element to be effected, instead of placing the passed number into the field or element. All other parameters are as decribed above.
When the user types, their input will automatically be converted in the correct format. This also attaches .val() hooks which allow you to continue using .val() to set your input elements, and you don't need to worry about handling the formatting.
Automatic paste formatting is also supported.
Writing numbers into an element
$('.selector').number( 1234, 2 ); // Changes the text value of the element matching selector to the formatted number.
출처 https://github.com/customd/jquery-number
'Story > Jquery' 카테고리의 다른 글
detect-mobile-devices 모바일 체크 (0) | 2015.09.21 |
---|---|
Disable or enable an input field with jQuery (0) | 2015.07.22 |
javascript 줄바꿈 처리 nl2br (0) | 2015.03.16 |
jQuery Selectbox plugin (0) | 2015.03.10 |
반응형 또는 모바일 페이지에 이미지맵(image map) 사용하기 (0) | 2015.02.26 |