Automatic type conversions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron

    Automatic type conversions

    I know now (thanks to this board) that there are numerous ways to force
    a type conversion from a string to a number (such as +, Number(), adding
    1, parseInt(), etc).
    I'm curious, though...is there any way to force a type conversion the
    other way, that is, from a number to a string? Previously, I've just
    been assigning numbers to the value property of whatever element I want
    to change, which seems to automatically force the appropriate type
    conversion (number to string). This seems sloppy though - is there a
    way to overtly force this type conversion without having to resort to this?

    Thanks,
    Aaron


  • Michael Winter

    #2
    Re: Automatic type conversions

    On Thu, 01 Apr 2004 13:57:53 -0800, Aaron <agchandler@com cast.not> wrote:
    [color=blue]
    > I know now (thanks to this board) that there are numerous ways to force
    > a type conversion from a string to a number (such as +, Number(), adding
    > 1, parseInt(), etc).
    > I'm curious, though...is there any way to force a type conversion the
    > other way, that is, from a number to a string? Previously, I've just
    > been assigning numbers to the value property of whatever element I want
    > to change, which seems to automatically force the appropriate type
    > conversion (number to string). This seems sloppy though - is there a
    > way to overtly force this type conversion without having to resort to
    > this?[/color]

    Concatenation with a string:

    var str = 6 + '';

    or using the String() constructor as a function:

    var str = String( 6 );

    will convert the number to a plain string. If you want to format the value
    as a floating-point number:

    <URL:http://jibbering.com/faq/#FAQ4_6>

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    Working...