I need to write currency values like $35.40 (thirty five dollars and forty cents)
and after that, i want to write some "****"
so at the end it will be:
thirty five dollars and forty cents*********
in a maximun of 100 characters
I've asked a question about something very likely but I couldn't understand the main command.
String format = String.format("%%-%ds", 100);
String valorPorExtenso = String.format(format, new Extenso(tituloTO.getValor()).toString());
What do I need to change on format to put *** at the end of my sentence?
The way it is now it puts spaces.
You may want to look at commons-lang http://commons.apache.org/lang/api-release/index.html
I'm under the impression that you want to pad this out to 100 characters.
http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringUtils.html#rightPad%28java.lang.String,%20int,%20java.lang.String%29
The other option is to create a base string of 100 '*' characters.
Create a string builder and do the following:
StringBuilder sb= new StringBuilder(new Extenso(tituloTO.getValor()).toString());
sb.append(STARS_STR);
String val= sb.substring(0, 100);
That should get out the value formatted out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With