How do I get System.out.format to print out doubles with the same precision

Using the System.out.format, how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println.
For example, take the following code:
double d = 12.48564734342343;       
System.out.format("d as format: %f\n", d);
System.out.println("d as   sout: " + d);Running the code, I get:
<font face="courier">
d as format: 12.485647
d as sout: 12.48564734342343
</font>
The precision of d has been lost.
I could bump up the precision as follows:
double d = 12.48564734342343;
System.out.format("d as format: %.14f\n", d);
System.out.println("d as   sout: " + d);That appears to work, I get:
<font face="courier">
d as format: 12.48564734342343
d as sout: 12.48564734342343
</font>
However, that solution fails if d has a different precision, say 12.48. In that case I get:
<font face="courier">
d as format: 12.48000000000000
d as sout: 12.48
</font>
So how do I get System.out.format to print out doubles with the same precision as System.out.println?
Thanks..

YoungWinston wrote:
Schmoe wrote:
Interesting, but this is not what I am looking for...Your original question was "how do I print out the value of a double such that it looks exactly like it does if it were print from a System.out.println", and you've been told how to do that (although the pattern given by sabre may be a bit excessive - you should only need 15 '#'s).The initial phrase from my question was "Using the System.out.format, how do I..".
It's worth remembering that, unlike the Format hierarchy, 'format()' is NOT native to Java. It's a convenience implementation of the 'printf()' and 'sprintf()' methods provided in C, and first appeared in Java 1.5. Those methods were designed to produced fixed-format output; 'println()' was not.Perhaps it is the case that this can't be done.
Furthermore, Double.toString(), which is what is used by println() does not produce the same format in all cases; format("%.14f\n", d) does. TrySystem.out.println(1.8236473845783d);
System.out.println(1823647384.5783d);and you'll see what I mean.I am fine with that. It still displays all the precision.
I am simply looking for a way to quickly print out multiple variables on a sysout while debugging. I want it as syntactically sweet as possible. System.out.println can be a pain when outputting multiple variables like the following:
"System.out.println("a: " + a + "; b:" + b + "; c: " + c);"
For some reason, my fingers always typo the plus key.
I was hoping that System.out.format would be easier,along the lines of:
"System.out.format("a: %f, b: %f, c: %f\n", a, b, c);"
From a syntactical sweetness point of view, it is easier. However, the %f on doubles truncates the precision. I figured there must be a way to get the full precision.
DecimalFormat is syntactically sour for this purpose, as you need to instantiate the DecimalFormat.
fwiw I have enjoyed reading the suggestions in this thread...

Similar Messages

  • How do you get FaceTime to work between two Mac's with the same email address? Thanks, Mike

    How do you get FaceTime to work between two Mac's with the same email address?

    I would like to know the same thing.  How does facetime work between a MacBook Pro and an I Pad that run off the same email address/mac id

  • How can i get Google maps back on, i lost them with the ios6 update, the new maps are terrible

    how can i get Google maps back on, i lost them with the ios6 update, the new maps are terrible

    It's still not known if and when Google Maps becomes available in the AppStore. This is today's story: http://www.macrumors.com/2012/09/25/google-has-not-yet-submitted-a-google-maps-a pp-to-apple/

  • How can i get my iPhone, ipad mini and mac to show the same  contacts calendar and notes

    how can i get my iPhone, ipad mini and mac to show the same  contacts calendar and notes

    Plug the phone and iPad into your computer and sync them.

  • I have a Creative D100 wireless speaker.  How do I get my bluetooth on my Mac to work with the speaker.  It doesn't appear to recognize the speaker.

    I have a Creative D100 wireless speaker.  How do I get my bluetooth on my Mac to work with the speaker.  It doesn't appear to recognize the speaker.

    Have you gotten in touch w/the speaker manufacturer?  Their response? 

  • How can i get my iMessage on my mac to sync with the texts i get on my iPhone?

    how can i get my iMessage on my mac to sync with the texts i get on my iPhone?

    Welcome to the Apple Community.
    Are you aware it only syncs iMessages. Also once enabled only new messages will sync, try messaging the user from the Mac and see if that gets things going for you.

  • Web Matrix FTP Remote Connection Error - "Connection Error - Failure to get file list from server. An entry with the same key already exists."

    Does anyone have experience with this issue when connecting to a Linux FTP Web Server running a FTP Site?
    "Connection Error - Failure to get file list from server. An entry with the same key already exists."
    I cannot access the root directory of the ftp file server using Web Matrix 3. The site is .php based, and
    is accessible when connecting with FileZilla or Remote Connecting via FTP with Visual Studio.
    All sites have been deleted from Web Matrix, the user Application Data has been cleared and Web Matrix has been reinstalled.
    Issue Persists....
    Thanks in advance,
    Justin

    Turns out that the program leaves metadata in your app data folder that is not removed upon uninstallation of the software.
    This is incorporated to communicate with a file that uploaded into the ftp directory when publishing pages.

  • How do you create aligned interactive text boxs in a PDF with the same width and height?

    how do you create aligned interactive text boxs in a PDF with the same width and height?
    Without free hand creating the sizing?

    Assuming by "interactive text boxes" you mean form fields; in Acrobat, make a form field, then copy it and paste. (GIve the pasted copy a different name so they don't genetate the same field feedback.) Now you have two fields of the exact same size. Shift-click or marquee-drag to select both, then right-click and choose a command from the Align, Distribute or Center menu.

  • How can I delete my apple id and create another one with the same email?

    How can I delete my apple id and create another one with the same email?

    So sorry; somehow I forgot to provide the link.   Here it is ...
    Frequently asked questions about Apple ID
    Again, my apologies.

  • Can a standard Adobe ID Suite be installed on more than one computer? If not; how can an educator buy a second seat on another computer with the same educators account?

    Adobe requires an ID account to install software on a single computer. However I have a portable Mac as well as a desktop system. Can I install another copy with the monthly paid installation on the second computer or do I need to buy another seat with the same account?
    J-GM

    Hey tferm78!
    I have a couple of options for you to consider. First, you may simply want to authorize all of your computers for your iTunes account and turn on Automatic Downloads, so that when you download something on one computer, it will automatically download to other computers:
    iTunes Store: Authorize or deauthorize your Mac or PC
    http://support.apple.com/kb/ht1420
    iTunes Store: How to enable Automatic Downloads
    http://support.apple.com/kb/ht4539
    You could also look into iTunes Match, a service that would seamlessly link all of your iTunes libraries:
    Apple - iTunes - Match
    http://www.apple.com/itunes/itunes-match/
    Lastly, here is an article that will help you move your library from one computer to another, if you so desire:
    iTunes: How to move your music to a new computer
    http://support.apple.com/kb/ht4527
    Thanks for using the Apple Support Communities. Have a good one!
    -Braden

  • How can I see My Photo Stream from two Macs associated with the same Apple ID?

    I have a MacBook Pro (my personal machine) and an iMac (our family computer).
    The iPhoto library housing all of our family photos lives on the iMac.
    The iPhoto library on my MacBook Pro is currently empty.
    I have an account on both machines.  I have associated the same Apple ID with both machines.
    When I launch iPhoto on my MacBook Pro and attempt to turn on photo sharing (so that I can see My Photo Stream, as well as other shared streams), iPhoto informs me that "iCloud Photos for xxx@xxx is being used with another library named 'iPhoto Library'."
    My iPhone, which is also affiliated with the same Apple ID, shows the streams just fine.
    What can I do to remedy this situation?  I'd like to be able to view my shared streams on my MacBook Pro, while leaving the actual massive photo library on the iMac.

    I found out about this issue when I created a new library with some photo's I wanted to sync to my iCloud account.  I found the following on the Fat Cat Software page and thought it might be helpful to others:
    Using Photo Stream with multiple libraries
    Starting in iPhoto 9.2, Apple introduced a new feature called Photo Stream, which lets you automatically transfer photos via their iCloud service between your iPhoto library and your other devices such as an iPhone, iPad, or another Mac. This feature works when you have multiple iPhoto libraries set up, but there are a couple things to be aware of.
    First, iPhoto will only allow Photo Stream to be active in one iPhoto library at any given time. If you've already enabled Photo Stream in one library, but then open a second library and enable Photo Stream there, this will cause Photo Stream to be turned off in the first library.
    Any photos downloaded by Photo Stream are actually stored in an entirely separate location from any of your iPhoto libraries. This means that, even if you do switch Photo Stream from one library to another, you will not need to go through redownloading all the photos you already have in Photo Stream back from the iCloud servers. So, switching Photo Stream from one library to another is a relatively inexpensive operation, so you can do it as often as needed without it being much of a hassle.

  • One User gets error Message saving an Incident, another user with the same rigthts not

    Hi there,
    We have a user sometimes getting an error message (see beyond) when saving an Incdient eg. only modified the descrition field. The user is able to create, update and resolve all other incidents. The user also may have changed this incident before.
    When we use an other user with the same rigths, this user is allowed to modify the description field (and others)
    We tested: The behavoir does not change for the first user, after the second user changed something.
    It's not the workflow for the first assigned to date
    No other user tries to use this incidents
    We have a custom field, but it is not used in this case (so I know Romans SQL
    http://social.technet.microsoft.com/Forums/systemcenter/en-US/401c8083-cd4d-4a74-b300-74f18caaa6a3/kb-2525307-for-2012?forum=systemcenterservicemanager)
    Had a "powershell look" at the incident, but I did not see something "special" about this incident.
    Anyone an idea, where to look at?
    Finaly the Error Message:
    Date: 11.02.2014 09:58:48
    Application:
    Application Version: 7.5.2905.0
    Severity: Error
    Message:
    Microsoft.EnterpriseManagement.Common.UnauthorizedAccessEnterpriseManagementException: The user DOM\xxxxx does not have sufficient permission to perform the operation.
       at Microsoft.EnterpriseManagement.Common.Internal.ServiceProxy.HandleFault(String methodName, Message message)
       at Microsoft.EnterpriseManagement.Common.Internal.ConnectorFrameworkConfigurationServiceProxy.ProcessDiscoveryData(Guid discoverySourceId, IList`1 entityInstances, IDictionary`2 streams, ObjectChangelist`1 extensions)
       at Microsoft.EnterpriseManagement.ConnectorFramework.IncrementalDiscoveryData.CommitInternal(EnterpriseManagementGroup managementGroup, Guid discoverySourceId, Boolean useOptimisticConcurrency)
       at Microsoft.EnterpriseManagement.ConnectorFramework.IncrementalDiscoveryData.Commit(EnterpriseManagementGroup managementGroup)
       at Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.EnterpriseManagementObjectProjectionWriteAdapter.WriteSdkObject(EnterpriseManagementGroup managementGroup, IList`1 sdkObjects, IDictionary`2 parameters)
       at Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.SdkWriteAdapter`1.DoAction(DataQueryBase query, IList`1 dataSources, IDictionary`2 parameters, IList`1 inputs, String outputCollectionName)
       at Microsoft.EnterpriseManagement.UI.ViewFramework.SingleItemSupportAdapter.DoAction(DataQueryBase query, IList`1 dataSources, IDictionary`2 parameters, IList`1 inputs, String outputCollectionName)
       at Microsoft.EnterpriseManagement.UI.DataModel.QueryQueue.StartExecuteQuery(Object sender, ConsoleJobEventArgs e)
       at Microsoft.EnterpriseManagement.ServiceManager.UI.Console.ConsoleJobExceptionHandler.ExecuteJob(IComponent component, EventHandler`1 job, Object sender, ConsoleJobEventArgs args)
    Patrick Wahlmüller

    take a look at
    this similar issue and see if the same process can help with your issue.

  • How do I face time from my iphone to my mac with the same apple id?

    how do i facetime from my iphone 4s with my mac at home with the same apple id

    On your Mac computer you would need Osx 10.6.6.  You would identify your Mac with an email address which would be used as the Mac's calling Id.  For the iphone you would simply use its telephone number as the calling Id.  Actually you can use a separate, individual e-mail also, but it certainly makes sense to use the already assigned tel #.
    Wuz

  • How do I get my icloud login and apple ID to be the same?

    My login and apple ID for all my deivces match.  It is just when I login to the iCloud.com where the Apple ID is not the same...  kinda wierd

    Hello there SciFii,
    I recommend logging into http://appleid.apple.com with the Apple ID that you use on your devices. What you are looking for is the email address that you log into icloud.com with. If it is there, then great! You can use either one to log into your devices, or icloud.com.
    If it is not there and the email you use at icloud.com is its own Apple ID, then I need to point out this section of the iCloud FAQ:
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    If you are wondering how using multiple Apple IDs relate to iCloud, see Apple IDs and iCloud.
    All the best,
    Sterling

  • HT5868 How do I get my iPhone to "always" trust my laptop (using the same USB port) if I don't have iTunes?

    I only connect my iPhone to one laptop; I plug it into the same USB port each time. I do not have (nor do I want) iTunes on this laptop. Hence each time I plug the iPhone into my laptop I have to enable it and hit "Trust". How do I get the iPhone to recognize my laptop indefinitely and only ask the trust question if I ever plug into a different device?

    As far as I know you cannot do so.  The "Trust" setting is actually stored as a line entry in the iTunes preference file.  No iTunes, and there is no Preferences file to record your choice.

Maybe you are looking for

  • Need help with java

    ok so i have a midterm and need help this question that is gonna be on the midterm. i dont know how to do it and its worth 16 marks!!!! here it is the UW Orchestra wants to produce a CD containing all the pieces of music from its upcoming concert. In

  • Paging Problem in JSP using request.

    Dear Friends, I have an issue in JSP paging using request. In my action servelet my code is set as follows. request.setAttribute("clients", clients); In JSP I have <%ClientDataBean[] clients = (ClientDataBean[]) request.getAttribute("clients"); If I

  • Changes made to the database are not being affected in Toplink work bench..

    Hi, Im recently encountering the following problem with Toplink mapping work bench. The cchanges are not visible when I make any changes to the underlying database tables and retrieve that tables into mapping work bench . The retrived table informati

  • How to automatically ad/drop a table on an existing replication?

    Hi! I would like to have a replication for my database (in SQL Server 2008 R2), which automatically add/drop tables at the subscriber (without needing me to manually change the publication properties and articles items) as soon as I add/drop at the p

  • "The disk cannot be partitioned because some files cannot be moved" error

    So I am trying to partition my macbook pro and it says that it is already journaled (I think?) but I get this error message "Back up the disk and use Disk Utility to format it as a single Mac OS Extended (Journaled) volume. Restore your information t