cancel
Showing results for 
Search instead for 
Did you mean: 

Converting from double to float

Former Member
0 Kudos

Hi,

I have requirment where third party system sends the value in double but SAP BAPI need in float format. Can any explain how can we do using the UDF.

Thanks,

Venkat

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Venkat,

do below in UDF - Take input argument String a - write below in UDF:

Double d = new Double(a);

float f = Double.floatValue(d);

return Float.toString(f);

Thanks,

Rajeev Gupta

Former Member
0 Kudos

Rajeev,

Getting following error when I try,,can you please help me..in resolving..

Source code has syntax error: /usr/sap/XD1/DVEBMGS21/j2ee/cluster/server0/./temp/classpath_resolver/Mapcf401390d7bf11dbc695001125392936/source/com/sap/xi/tf/_test_.java:70: cannot resolve symbol symbol : method floatValue (java.lang.Double) location: class java.lang.Double float f = Double.floatValue(d); ^ 1 error

Former Member
0 Kudos

try this

Double d = new Double(a);

float f = new Float(d);

return f.toString(f);

Sreeram Reddy

Former Member
0 Kudos

Hi Venkat,

in graphical mapping do below:

source field ->MapWithDefault->UDF->Output field

double click MapWithDefault and specify 0......just check your source data is having valid data for double field.........

use below code for UDF:

Double d = new Double(a);

float f = d.floatValue();

return Float.toString(f);

Thanks,

Rajeev Gupta

Message was edited by:

RAJEEV GUPTA

Former Member
0 Kudos

Hi Venkat,

use my latest UDF code from above.......then you will get your desired output.....

Thanks,

Rajeev Gupta

Answers (2)

Answers (2)

Former Member
0 Kudos

Try this


Float floatVal = new Float(doubleVal);
float num = floatVal.floatValue();

Hope this help

Francesco

Former Member
0 Kudos

Hi,

In UDF, we have to wrok with strings only. When convert to string, getting error ,Float can not be deferenced...

Former Member
0 Kudos

Venkat

float f = (float)a;

return f.toString();

Regards,

Jai Shankar

Former Member
0 Kudos

convert it to string using toString function or do this way return result = f+ ""; this will also work.

Former Member
0 Kudos

Hi,

You can use the constructor directly Float f = new Float(double value)..

If the value is a double object, then you can get the double value as

double d = "your entered Double Object".doubleValue()

Another way is to type cast Float f = (Float) double value...

Hope this helps..

Regards

Kiran..