In this section, we will learn how to convert numbers to String.
Convert Number to String
In this section, we will learn how to convert numbers to String. The following program provides you the functionality to convert numbers to String.
Code Description:
In this program we have declared different type of numbers like float, int, long etc as shown below. We have used "valueOf()" method here which is a method of String class. We use "String.valueOf()" for numeric conversions and "toString()" method to convert these numeric classes to String as shown in the code below.
Here is the code of the program:
class NumToStr {
|
Output of the program:
C:\unique>javac NumToStr.java C:\unique>java NumToStr int i = 40 float f = 100.0 long l = 3000000 int i = 40 float f = 100.0 long l = 3000000 C:\unique> |