| Author |
"printf" applied to a float using a Parameter
|
Wolfgang Obi
Ranch Hand
Joined: Dec 05, 2005
Posts: 134
|
|
Hi , i would please like to know if it is possible to replace the "2" (bold/italicised - see below) with a variable for example "afterKomma"?...if yes, how do i implement this, if no, what other (better?) options do i have ? what i'm asking basically is how can i realise something like this: thanks  [ June 18, 2006: Message edited by: Wolfgang Obi ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
I trust you have been through the API specifications about the % tags? Look in the java.util.Formatter class. Then tell us how you sorted out the problem.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
. . . and for variable numbers after the decimal point . . . Difficult . . . You will have to go to the NumberFormat or DecimalFormat classes and see whether you can find any methods which allow you to set digits in the fraction. There is a silly example on this website from another German chap. Look at it.
|
 |
Wolfgang Obi
Ranch Hand
Joined: Dec 05, 2005
Posts: 134
|
|
Hey Ritchie, thanks once again for all the help and prodding in the right direction ... here's how i finally solved the problem: [ June 18, 2006: Message edited by: Wolfgang Obi ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Glad to be able to help
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
Another way you could have solved this: Note that the string "%.2f\n" is just a String object. It does not have to be a literal string; you can pass any other String object instead.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Wolfgang Obi
Ranch Hand
Joined: Dec 05, 2005
Posts: 134
|
|
thanks jasper. looks less complicated :-) cheers- -W.O.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Another way you could have solved this:
I wish I had thought of that Quite right.
|
 |
 |
|
|
subject: "printf" applied to a float using a Parameter
|
|
|