Cars & Trucks Logo

Related Topics:

Dion Wanda Posted on Nov 21, 2012

How can I format a java string using a width variable?

I want to know about format a java string using a width variable. Please give me more information.

1 Answer

Anonymous

Level 1:

An expert who has achieved level 1.

New Friend:

An expert that has 1 follower.

  • Contributor 1 Answer
  • Posted on Nov 21, 2012
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

New Friend:

An expert that has 1 follower.

Joined: Nov 21, 2012
Answers
1
Questions
0
Helped
142
Points
1

The Entities in java are slightly different. I adore them being included (finally).

float bigNum = 123456.789012;

String pattern = String.format( "%10.2f is my magic number%n", bigNum);

System.out.println( pattern);

or

System.out.println(

String.format( "%10.3f", bigNum) );

the "decimal place" is the rounding.

lead off with a zero to get leading zeroes

String.format("%03.2f", bigNum));

if I want evenly spaced columns, I have to construct an Object[] array

array[0] = salaryAmt;

array[1] = hourly Rate;

array[2] = "Cowboy Bob";

System.out.println(

"%5.2f,%3.2d,%s%n, array);

Here you will get more information about java string format.

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

152 views

Ask a Question

Usually answered in minutes!

Top Jeep Experts

Kirk Augustin
Kirk Augustin

Level 3 Expert

2020 Answers

john h

Level 3 Expert

29497 Answers

Arnie Burke
Arnie Burke

Level 3 Expert

7373 Answers

Are you a Jeep Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...