String zu Float und Float wieder zu String

Hallo Leute,

von String zu Float ist kein Thema,

aber wie parse ich von Float zu String?

Grüße Erich

Salü Erich

Die einfachste Variante:

float x = 3.22324;
String y = x + „“;

Grüsse
Andrea

Hallo -

Die einfachste Variante:
float x = 3.22324;
String y = x + „“;

Die saubere Variante:

float x = 3.1415926535;
String s = Float.toString(x);

Genauso andersrum:

String s = ‚3.1415926535‘;
float x = Float.valueOf(s).floatValue();

wobei Float.valueOf eine NumberFormatException werfen kann:

String s = ‚3.1415926535‘;
float x = 0.0f;

try {
x = Float.valueOf(s).floatValue();
} catch (NumberFormatException ex) {
System.err.println(‚Falsches Nummernformat‘);
}

lg,

J.P.Jarolim

Ja Servus,

ist zwar quick und dirty…
aber es funzt :wink:

Muss das aber noch richtig parsen…

Bei Kommazahlen stürzt mir die ganze Geschichte ab…

Grüße Erich

der sagt zu mir:
the method toString(float) in the type Float is not applicable for the arguments float…

Float summe = w1 + w2 …;

string totalsumme = Float.toString(summe);

DEM FUNZT

habe float gross geschrieben !
Dem FUNZT !

:wink: erich