Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting my String

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.

like image 438
Gondim Avatar asked Dec 07 '25 09:12

Gondim


1 Answers

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.

like image 143
Dave G Avatar answered Dec 09 '25 23:12

Dave G