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 8969095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:32:42+00:00 2026-06-15T17:32:42+00:00

Recently, while doing a printer layout programmatically in Java, I stumbled across the problem

  • 0

Recently, while doing a printer layout programmatically in Java, I stumbled across the problem of aligning certain numbers and to have them right-aligned I needed to have a count of the amount of digits in each number. What would be the easiest way to do this?

  • 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-15T17:32:43+00:00Added an answer on June 15, 2026 at 5:32 pm

    While I was breaking my head over an algorithm on how to do this the simplest, a friend of mine pointed out a very simple solution: simply put the number in a string and count its length ;-). No need to make things hard on yourself with mathematical formulas! In Java for example:

    String number_s = ""+number;
    int digits = number_s.length();
    

    This can be applied to decimal numbers aswell, after splitting the string on the separating delimiter (usually . or ,).

    Hope I can save at least someone some time with this.

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

Sidebar

Related Questions

I recently stumbled across this problem while testing my C# program. parsing ) -
I have been using GQuery for a while now. I recently came across some
recently, while working on a db2 -> oracle migration project, we came across this
Recently I have modified my code to While taking input form STDIN, I moved
I recently stumbled upon Play framework while evaluating frameworks to use in a project.
I have been recently trying to use svm for feature classification. While i was
While doing some forensics archeological survey in an old apps I have to maintain
I have used svn for a while but recently a couple teams were added
I have recently been doing some circle detection in OpenCV and I have had
I've been doing a lot with web optimization recently, and I've come across an

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.