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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:39:49+00:00 2026-06-14T05:39:49+00:00

I have the following code: String curDir = .; File fileObject = new File(curDir);

  • 0

I have the following code:

String curDir = ".";
File fileObject = new File(curDir);
File[] fileList = fileObject.listFiles();

float fileLengthMegabytes = (float)fileList[i].length() / 1000000;

The method fileList[i].length() returns 311 bytes as the type Long.

The previous code results in the following output:

3.88E-4

How do I get my expected output of 0,000311 inside the fileLengthMegabytes variable?

  • 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-14T05:39:50+00:00Added an answer on June 14, 2026 at 5:39 am

    That is Scientific Notation.

    AND you are getting 388 instead of 311 because you are dividing by 1000000 instead of 1048576 (1024 * 1024)

    EDIT: 311 is not achieved even with 1048576, that way you get 370… so the error is probably in your calc 😉

    As described here , you just have to convert your Scientific Notation to a Decimal Notation through a Formatter.

    DecimalFormat df = new DecimalFormat("#.########");
    return df.format(fileLengthMegabytes);
    

    Running Example: http://ideone.com/2lkKv7

    import java.util.*;
    import java.lang.*;
    import java.text.*;
    
    class Main
    {
        public static void main (String[] args) throws java.lang.Exception
        {
                    DecimalFormat df = new DecimalFormat("#.##########");
    
            float fileLengthMegabytes1 = (float) 388 / 1000000;
            float fileLengthMegabytes2 = (float) 388 / 1048576;
            System.out.println("MB1 in Scientific Notation: " + 
                                fileLengthMegabytes1);        
            System.out.println("MB1 in Decimal Notation: " + 
                                df.format(fileLengthMegabytes1));
            System.out.println("MB2 in Scientific Notation: " + 
                                fileLengthMegabytes2);        
            System.out.println("MB2 in Decimal Notation: " + 
                                df.format(fileLengthMegabytes2));
            }
    }
    

    Output:

    MB1 in Scientific Notation: 3.88E-4

    MB1 in Decimal Notation: 0.000388

    MB2 in Scientific Notation: 3.7002563E-4

    MB2 in Decimal Notation: 0.0003700256

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

Sidebar

Related Questions

Have the following code: String s= v.request(engine/?key=, P4z72NmBa91&method=load); JSONParser parser = new JSONParser(); Object
Ok so I have the following code: string numbers = File.ReadAllText(numbers.txt); StringSplitOptions.RemoveEmptyEntries); List<string> List
I have the following code: string path = ~/Others/Muzica/Demo/+interpret+_+album+/; CMSUtils.CreateFolder(MapPath(path)); where CreateFolder method is
I have the following code: String table; private DB.ConnectMAS mas=new DB.ConnectMAS(); java.sql.ResultSet rs1 =
I'm trying to send a file using ftp. I have the following code: string
I have the following code: string filterTerm = txtDocFilterTerm.Text.ToLower(); var regEx = new Regex(filterTerm);
I have the following code: std::string cmd = sudo chmod a+x file; int r
I have the following code: string[] files = Directory.GetFiles(@C:\Notes, *.txt, SearchOption.TopDirectoryOnly); foreach(string file in
I currently have the following code: string user = @DOMAIN\USER; string[] parts = user.Split(new
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);

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.