Good afternoon I have the following code
static String neto = "";
static String tara = "";
static String bruto = "";
Enviar_datos enviar = new Enviar_datos(conf);
String bascula = conf.getBascula();
if (control == 0) {
conf.CargarConfiguracion();
bascula = conf.getBascula();
tara = leido_final;
System.out.println("tara:" + tara);
lf1 = Double.parseDouble(leido_final);
}
if (control == 1) {
neto = leido_final;
System.out.println("neto:" + neto);
lf2 = Double.parseDouble(leido_final);
}
if (control == 2) {
double brutoi = lf1 + lf2;
bruto = String.valueOf(brutoi);
enviar.setPeso_neto(bascula + tara + neto +bruto);
enviar.converir_datos();
control = 0;
}
}
my program registers the variables with a scale with the following format 0.000 my question is how can I fill with zeros to the left to give it the following format 0000000000.000
As such in a data type
Double
I don't know of a possible way to do it. The method that works, is to pass it to a typestring
and add them manually. I share a function that I once used for this:What this method does, is that you send it 2 variables, a variable
string
that is the string, and a variablelargo
that is the length that your string should be, with the 0's appended to the left.If you need more information, I looked it up from This question on an external site
java.text.DecimalFormat class, used to format numbers.
https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html
To get the formatted number:
Greetings.