#5288 closed enhancement (wontfix)
Add jQuery.num() function to cast value to number (int/float)
Reported by: | andre1 | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | core | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Add a simple function to cast value to number, either as jQuery.num( <value>[, <onFalse=0>[, <type=float|int>]] ) or as separate functions jQuery.int( <value>[, <onFalse=0>] ) and jQuery.float( <value>[, <onFalse=0>] ).
Bellow follows example functions:
function int(value, onFalse) { // Checks if value is int, if not onFalse or 0 is returned value = parseInt( value ); return isNaN( value ) ? ( onFalse !== undefined ? onFalse : 0 ) : value; } function float(value, onFalse) { // Checks if value is float, if not onFalse or 0 is returned value = parseFloat( value ); return isNaN( value ) ? ( onFalse !== undefined ? onFalse : 0 ) : value; }
Change History (6)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Feels unnecessary to me. It's one line to do in pure JS. Why clutter the source with methods for it?
comment:3 Changed 13 years ago by
Sounds like a feature that could be easily handled by a non jQuery method. It doesn't really relate to any of the things jQuery is really good at other than its in Javascript.
comment:4 Changed 12 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This is not appropriate for jQuery core.
comment:5 Changed 10 years ago by
Feels unnecessary to me. It's one line to do in pure JS. Why clutter the source with methods for it?
This should be reconsidered. It may only be one line of pure JS, but I'd prefer to push that one line up into jQuery rather than having to litter my code with 100's of lines like this:
parseInt($('selector').val(), 10);
comment:6 Changed 10 years ago by
I fail to see how
jQuery.num( $("selector").val(), 0, "int" );
is a preferable form of "litter."
"onFalse" should have been "onNaN"