TypeScript | toString() Function

The toString() method in TypeScript is used to returns a string representing the specified object radix (base).

Syntax:

number.toString( [radix] )

Parameter: This function accept asingle parameter as mentioned above and described below:

  • radix: This parameter represents an integer between 2 and 36 specifying the base to use for representing numeric values.
  • Return Value: Returns a string representing the specified Number object.

    Below examples illustrates the toString() function in TypeScript



    Example 1:

    javascript

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // The toString()function
    let Num1: number = 123;
    Num1.toString(); 
    Num1.toString(16); 
    Num1.toString(8); 
    Num1.toString(4);

    chevron_right

    
    

    Output:

    123 
    7b
    173
    1323
    

    Example 2:

    javascript

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // The toString() function
    let Num2: number = 12345;   
    console.log("Number Method: toString()");  
    console.log(Num2.toString());  
    console.log(Num2.toString(4));

    chevron_right

    
    

    Output:

    Number Method: toString()
    12345
    3000321
    

    full-stack-img

    My Personal Notes arrow_drop_up


    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.