How do I change my numbers at the end so that instead of showing 0 it shows 0.00 or instead of showing 5.3 it shows 5.30?
I want only the winnings to be showing in this format.
import java.util.Scanner; public class part1 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); double stake; String horsesName; double outrightWinOrEachWay; double outrightWin; double eachWay; double OddsX; double OddsY; double totalOdds; double eachWayOdds; double runners; double finishingPosition; double winnings; double win; double place; System.out.println("Please enter your stake:"); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } stake = keyboard.nextFloat(); horsesName = keyboard.nextLine(); while ( horsesName.isEmpty() ) { System.out.print("What is your horses name?"); horsesName = keyboard.nextLine(); } horsesName = horsesName.toUpperCase(); System.out.println("Enter the betting odds (x/y)"); System.out.println("X="); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } OddsX = keyboard.nextFloat(); System.out.println("Y="); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } OddsY = keyboard.nextFloat(); totalOdds = (OddsX/OddsY); System.out.println("How many runners are in the race?"); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } runners = keyboard.nextFloat(); System.out.println("What is your finishing position?"); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } finishingPosition = keyboard.nextFloat(); System.out.println("Is your bet a:"); System.out.println("(1) Outright Win"); System.out.println("(2) Eachway"); while (! keyboard.hasNextDouble() ) { keyboard.nextLine(); System.out.print("Please try again "); } outrightWinOrEachWay = keyboard.nextFloat(); if (outrightWinOrEachWay == 1) { if (finishingPosition == 1) { winnings = stake + (totalOdds * stake); System.out.println(horsesName + " finished 1st out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition > 1) { System.out.println("Sorry you didn't win"); } } if (outrightWinOrEachWay == 2) { if (runners < 7) { eachWayOdds = (totalOdds/2); if (finishingPosition == 1) { win = stake + (totalOdds * stake); place = stake + (eachWayOdds * stake); winnings = win + place; System.out.println(horsesName + " finished 1st out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==2) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 2nd out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition> 2){ System.out.println("Sorry you didn't win"); } } if (runners >= 8 && runners <=20) { eachWayOdds = (totalOdds/3); if (finishingPosition == 1) { win = stake + (totalOdds * stake); place = stake + (eachWayOdds * stake); winnings = win + place; System.out.println(horsesName + " finished 1st out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==2) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 2nd out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==3) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 3rd out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition >3) { System.out.println("Sorry you didn't win"); } } if (runners >20) { eachWayOdds = (totalOdds/4); if (finishingPosition == 1) { win = stake + (totalOdds * stake); place = stake + (eachWayOdds * stake); winnings = win + place; System.out.println(horsesName + " finished 1st out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==2) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 2nd out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==3) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 3rd out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition ==4) { winnings = stake + (eachWayOdds * stake); System.out.println(horsesName + " finished 4th out of " + runners + " runners"); System.out.println("You have won \u20ac" + winnings); } if (finishingPosition >4) { System.out.println("Sorry you didn't win"); } } } } }
--- Update ---
Also how do I fix the place where it shows my java cause I forgot?