home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / misc / 3072 < prev    next >
Encoding:
Internet Message Format  |  1992-07-31  |  1.9 KB

  1. Xref: sparky comp.unix.misc:3072 comp.unix.programmer:4046 comp.unix.questions:9652
  2. Newsgroups: comp.unix.misc,comp.unix.programmer,comp.unix.questions
  3. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!sunova!falcon!rupen
  4. From: rupen@falcon.ssc.gov (Rupen Sheth)
  5. Subject: Is there a strtof() function (str to float)?
  6. Message-ID: <1992Jul31.201313.11253@sunova.ssc.gov>
  7. Originator: rupen@falcon
  8. Sender: usenet@sunova.ssc.gov (News Admin)
  9. Nntp-Posting-Host: falcon.ssc.gov
  10. Organization: Superconducting Super Collider Laboratory, Dallas
  11. Date: Fri, 31 Jul 1992 20:13:13 GMT
  12. Lines: 37
  13.  
  14. Hi:
  15.     Env: Sun Sparc.
  16.  
  17.     In trying to convert a string to a floating number, I don't always
  18.     get the exact value.
  19.  
  20.     For example:
  21.     float value;
  22.     char  str[10];      /* Say, str = "+0.02" */
  23.  
  24.     sscanf(str, "%g", &value);
  25.     OR
  26.     sscanf(str, "%f", &value);
  27.  
  28.     value is 0.0199999995529651642
  29.  
  30.     Is there a strtof() function that can convert a string to a float?
  31.     If not, is there another way I can convert a string %f or %g to a
  32.     float without these rounding errors?
  33.  
  34.     I am sure there is a way around this that I am not aware of.
  35.     Please help !!!
  36.     Respond by email to the address below.
  37.  
  38. Thank you.
  39. ---
  40. Rupen Sheth
  41. -------------------------------------------------------------------------------
  42. Superconducting Super Collider Laboratory        EMail: rupen@falcon.ssc.gov
  43. 2550 Beckleymeade Ave. MS 4004                   Phone: (214) 708-3344
  44. Dallas, TX 75237                                   FAX: (214) 708-4827
  45. -------------------------------------------------------------------------------
  46. -- 
  47. Rupen Sheth
  48. -------------------------------------------------------------------------------
  49. Superconducting Super Collider Laboratory        EMail: rupen@falcon.ssc.gov
  50. 2550 Beckleymeade Ave. MS 4004                   Phone: (214) 708-3344
  51.