8 Replies Latest reply: Sep 11, 2008 8:45 PM by 843785 RSS

    How can I configure my Double variables to a set length?

      Alright. Let me start by saying : I'm totally new to Java. The only experience I have is two weeks in the introductory course that I'm currently taking at my high school. So, sorry if I make a ton of errors, or don't understand certain things you say.

      Now, on to the problem.

      I'm making a calculator of sorts as a project for the aforementioned introductory course. I'm using double as the variable type. I'm trying to limit the answers to a set number of spaces. To do that, I'm currently using Decimal Format:
      df=new DecimalFormat("#####.##");
      Which works great for limiting answers to a certain amount of decimal spaces. However, the front part of the answer, before the decimal point, constantly changes, based on the numbers entered.

      I'm wondering if there's a way to set all of the unused places in Decimal Format to equal zeros, so that all of my answers will be the same length. For example,
      instead of returning 103.21 for an answer, it would return 00103.21.

      Thanks! (And sorry for whatever confusion I may have caused, heh.)