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

  • Home
  • SEARCH
  • 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 6803061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:17:55+00:00 2026-05-26T19:17:55+00:00

I am working on a problem which was given to me by my friend.

  • 0

I am working on a problem which was given to me by my friend. I need to take the input number in the form x.yzw*10^p where p is non zero and x.yzw can be zeros. I have made the program but the problem is that when we have numbers such as 0.098, decimal format will make it 9.8 but I need to get it to be 9.800, it has to always be outputted as x.yzw*10^p. can someone please show me how this is possible.

input:    output:
1234.56   1.235 x 10^3
1.2       1.200
0.098     9.800 x 10^-2

Code:

 import java.util.Scanner;
    import java.math.RoundingMode;
    import java.text.DecimalFormat;

public class ConvertScientificNotation {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        DecimalFormat df = new DecimalFormat("0.###E0");
        double input = sc.nextDouble();
        StringBuffer sBuffer = new StringBuffer(Double.toString(input));

        sBuffer.append("00");
        System.out.println(sBuffer.toString());
        StringBuffer sb = new StringBuffer(df.format(Double.parseDouble(sBuffer.toString())));

        if (sb.charAt(sb.length()-1) == '0') {
            System.out.println(sBuffer.toString());
        } else {
            sb.replace(sb.indexOf("E"), sb.indexOf("E")+1, "10^");
            sb.insert(sb.indexOf("10"), " x ");
            System.out.println(sb.toString());
        }
    }
}
  • 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-05-26T19:17:56+00:00Added an answer on May 26, 2026 at 7:17 pm
    DecimalFormat myFormatter = new DecimalFormat(".000");
    String output = myFormatter.format(input)
    

    then if you want to convert ‘output’ into a number, use:

    Float answer = Float.parseFloat(output)
    

    EDIT

    also check this out, it contains more information on how to format numbers

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

Sidebar

Related Questions

I am working on a problem in which I am given a number and
I'm working on a problem (in C++/opencv) in which 4 users need to be
i've been working on a problem for a while now, which involves targeting the
Real problem with an existing webapp which has been working for the last couple
I'm working on a problem where I need to store serialized hierarchies of Ruby
I'm working on a problem which we have to use semaphores to solve. I
I'm working on an app in which I need to scan through a string
I have a problem set for my programming class which I'm working on. The
I'm working on a project where I need to find which functions get called
I have written this method which given a number and a list will return

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.