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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:07:21+00:00 2026-06-17T09:07:21+00:00

I am using a pattern #0.00## to format numbers, it works as expected for

  • 0

I am using a pattern “#0.00##” to format numbers, it works as expected for most input. But sometimes sources number are smaller ie: 6.84378E-05, and gets converted into “0,0001”.

Is it possible to format only such numbers (not fitting standard pattern) using scientific notation? leaving all “normal” numbers intact? with single pattern.

I have to use only a single DecimalFormat pattern, without any extra code.

EDIT: To better explain why I need single DecimalFormat : I am using an external library and can only define a pattern to configure output.

  • 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-17T09:07:22+00:00Added an answer on June 17, 2026 at 9:07 am

    You can have distinct patterns only for positive and negative values.You should do something like:

    public class DecimalScientificFormat extends DecimalFormat {
        private static DecimalFormat df = new DecimalFormat("#0.00##");
        private static DecimalFormat sf = new DecimalFormat("0.###E0");
    
        @Override
        public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) {
            String decimalFormat = df.format(number);
            return (0.0001 != number && df.format(0.0001).equals(decimalFormat)) ? sf.format(number, result, fieldPosition) : result.append(decimalFormat);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basicaly I want to format a Date object using a specific pattern and the
I'm trying to write something that format Brazilian phone numbers, but I want it
Is there any way I can format a string into a specific pattern using
I'm using Directory.GetFiles() to list files according to given pattern. This works fine for
I need to parse a date from input string using date pattern yyyy-MM-dd, and
I need to format numbers (using WPF converters), and the only way I can
I try to have customized number format for US country. It works fine so
I'd like to format a duration in seconds using a pattern like H:MM:SS. The
I am using Pattern and Matcher classes from Java to parse a link file
I am using MVVM pattern and I have one DataGrid with a column which

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.