简体   繁体   中英

Java format all floats into a string

Here is my code:

float e[10]=new float[10];

Is there any way to format all the 10 floats into a format string? Maybe something like this in Python:

a=range(10)
print ('#'+'(%f)'*10+'#')%tuple(a)

Is there a method like this in java? I mean getting a string like "#(1.0)(2.0)(3.0)#" for the case of array_size 3.

float e[10]=new float[10];
System.out.println(Arrays.toString(e));

Try this

Try this , make a loop to the end of the array and parseFloat to a String msg

 String msg = "";
 float[] e= new float[10];
 for(int i=0;i<e.length();i++){
    msg = msg + Float.parseFloat(e[i]);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM