Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8191473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:55:39+00:00 2026-06-07T03:55:39+00:00

Sorry I was initially wanting to do it in php PHP integer part padding

  • 0

Sorry I was initially wanting to do it in php PHP integer part padding, but realised I will do it in Java in another part of code

So I need to format numbers with the integer part at least 2 chars

2.11 -> 02.11
22.11 -> 22.11
222.11 -> 222.11
2.1111121 -> 02.1111121

double x=2.11; 
System.out.println(String.format("%08.5f", x));

could do it, but it’s annoying the right trailing zeros, I would like to have an arbitrary large floating part

String.format("%02d%s", (int) x, String.valueOf(x-(int) x).substring(1))

is totally ugly and unexact (gives 02.1099…)

new DecimalFormat("00.#############").format(x)

will truncate floating part

thx for any better solutions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:55:40+00:00Added an answer on June 7, 2026 at 3:55 am

    the best I could come with is

    public static String pad(String s){
        String[] p = s.split("\\.");
        if (2 == p.length){
            return String.format("%02d.%s", Integer.parseInt(p[0]), p[1]);
        }
        return String.format("%02d", Integer.parseInt(p[0]));
    }
    

    pad(String.valueOf(1.11111118)) -> 01.11111118

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
sorry for the dummy question but I cannot find a simple and clean way
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this is a stupid question, but is there an easy way to
What I'm trying to achieve is that initially data will be loaded and then
UPDATE: Sorry, forgot to include some of the code (face-palm). I included it in
Sorry for wanting to ask a simple question. I have my initial view loaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.