DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2004
    Posts
    53

    Convert double to *chart

    I want convert double to char * string for insert in a .ini file

    Code:
    char mystring[50];
    double mydouble;
    
    sprintf(mystring, "%f", mydouble);
    It runs ok, but when I have a very small double (for example
    0.000000000000000000000000001)
    It convert to 0.00000000 (=0) and not to 1.0e-20
    Do you know how solve it?
    Thanks

    _______________________
    Hip Hop Directo
    Foros de musica

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    try to specify higher precision, say "%30.28f" which means 30 digits, 28 of which are for the fraction.
    Last edited by Danny; 10-26-2005 at 09:53 AM.
    Danny Kalev

  3. #3
    Join Date
    Nov 2004
    Posts
    53
    Thanks it is better but, I would like it puts something as 1.3e-20, is this posible?
    Thankss

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    yes, use the %e or %E format flags instead of %f.
    Danny Kalev

  5. #5
    Join Date
    Nov 2004
    Posts
    53
    This is the solucion "%e" in cientific mode
    Thanks

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    btw, you want to initialize your buffer before using it:

    char mystring[50] = {0};
    ...
    Danny Kalev

Similar Threads

  1. Need Help With Multi Function Program
    By WackoWolf in forum C++
    Replies: 4
    Last Post: 10-17-2005, 04:22 PM
  2. Replies: 3
    Last Post: 10-02-2005, 11:57 PM
  3. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 05:09 PM
  4. Replies: 0
    Last Post: 11-15-2001, 10:26 AM
  5. Double Text 1.0
    By George Gilbert in forum vb.announcements
    Replies: 0
    Last Post: 08-19-2001, 11:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links