Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting $ into formatted float java

I'm trying format a float to have a dollar sign in front of the number. Currently I'm trying to get it to print 150 spaces from the left side.

System.out.printf("%150.2f", orderTotal);

This is what I'm using but I can't figure out where to put the $ I guess I could make the entire thing into a String, but I was wondering if there is a way to do what I'm looking for?

like image 612
k3vy w3vy Avatar asked Dec 12 '14 01:12

k3vy w3vy


2 Answers

How about

System.out.printf("%150s", String.format ("$%.2f", orderTotal));
like image 183
Scary Wombat Avatar answered Sep 29 '22 19:09

Scary Wombat


System.out.printf("%150s$%.2f", "", orderTotal);
like image 21
Reimeus Avatar answered Sep 29 '22 19:09

Reimeus