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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:19:50+00:00 2026-05-29T04:19:50+00:00

I want to serialize/deserialize doubles to a readable String. I’m happy to lose any

  • 0

I want to serialize/deserialize doubles to a readable String. I’m happy to lose any accuracy beyond the 6th dp.

Whats the correct approach for doing this?

I’m concerned about System.out.println(1.03 – .42) printing 0.6100000000000001 and not 0.61.

Thxs.

  • 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-29T04:19:51+00:00Added an answer on May 29, 2026 at 4:19 am

    The simplest approach is to use PrintWriter and BufferedReader.

    double[][] doubles = new double[10][10];
    for(double[] ds : doubles)
        for(int i=0;i<ds.length;i++)
            ds[i] = Math.random() * 100;
    
    PrintWriter pw = new PrintWriter("double.tsv");
    for(double[] ds : doubles) {
        for(double d: ds)
            pw.printf("%.6f\t", d);
        pw.println();
    }
    pw.close();
    
    BufferedReader br = new BufferedReader(new FileReader("double.tsv"));
    String line;
    while((line = br.readLine())!=null) {
        String[] words = line.split("\t");
        for (String word : words) {
            double d = Double.parseDouble(word);
            System.out.print(d+"\t");
        }
        System.out.println();
    }
    

    prints

    72.520491   85.341994   21.958533   48.914986   14.959155   54.398293   54.438528   6.265907    77.654032   94.363109   
    65.594713   66.943443   69.891651   3.62663 13.445234   3.281239    99.897356   53.072258   11.931774   83.802643   
    17.387541   56.598334   90.104328   69.379567   95.631605   34.931461   73.336693   21.300139   50.511963   79.326218   
    61.844333   20.076352   81.668206   69.500067   45.936303   80.639298   86.534122   51.031074   89.718252   89.510961   
    41.923934   31.450051   35.373463   82.607984   69.796802   11.387551   28.684281   28.524173   3.926274    27.390139   
    43.116206   81.455006   52.424004   46.399187   84.572294   20.368705   7.414759    18.389408   91.835487   96.594918   
    87.632357   63.293224   8.751766    70.693449   12.30385    41.090964   93.36716    31.281827   95.411907   29.825814   
    46.516716   53.442007   18.273036   15.306335   87.773823   72.392803   85.34191    78.388259   80.203328   19.306142   
    93.249744   50.981212   7.02211 90.461556   46.307283   0.304891    33.055868   98.374818   33.050704   92.423133   
    41.791121   84.102962   37.881277   80.713237   24.856496   53.619386   99.447379   62.681776   14.927559   37.969094   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to serialize a nullable bool simply by converting it to a string
I want to serialize this class: public class CarDisplay { public string Name {
I want to be able to serialize/deserialize a generic list what I so far
I want to serialize/deserialize md5 context. But I don't know how to do it
I have some types that I want to serialize/deserialize and generate a UI based
I have a class that I want to have opportunities to serialize/deserialize. It implements
I really want this so I can serialize / deserialize some complex data objects
I'm currently convering my ASP.NET v2 application to serialize/deserialize it's objects because I want
I am using NetworkX to process large graphs. I want to serialize/deserialize those graphs,
Is there any way to serialize/deserialize an object DataContractJsonSerializer as well as ISerializeable interface.

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.