Java.lang.Float.valueOf() Method

Advertisements


Description

The java.lang.Float.valueOf(String s) method returns a Float object holding the float value represented by the argument string s.If s is null, then a NullPointerException is thrown.

Declaration

Following is the declaration for java.lang.Float.valueOf() method

public static Float valueOf(String s) throws NumberFormatException

Parameters

  • s -- This is the string to be parsed.

Return Value

This method returns a Float object holding the value represented by the String argument.

Exception

  • NumberFormatException -- if the string does not contain a parsable number.

Example

The following example shows the usage of java.lang.Float.valueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

     Float f = new Float("9.5");
     String str = "40.56";
     /* returns a Float object holding the value represented 
     by str */
     System.out.println("Value = " +  f.valueOf(str));
   }
}   

Let us compile and run the above program, this will produce the following result:

Value = 40.56



Advertisements
Advertisements