Help with data type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhankrish
    New Member
    • Dec 2006
    • 16

    Help with data type

    Hello all,
    I am supposed to multiply 10 float values. (like 0.002, 0.004, 0.006, etc...)
    Which data type will best suit the product of these float values?
    I used 'long double' but I am still getting 0 as the product.
    (I have initialised the product as 1. So, no problem with that.)
    Can someone suggest a suitable data type which can handle longer decimal places. Also pls mention the representation to be used ie.%f or something like that.
    Thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by madhankrish
    Hello all,
    I am supposed to multiply 10 float values. (like 0.002, 0.004, 0.006, etc...)
    Which data type will best suit the product of these float values?
    I used 'long double' but I am still getting 0 as the product.
    (I have initialised the product as 1. So, no problem with that.)
    Can someone suggest a suitable data type which can handle longer decimal places. Also pls mention the representation to be used ie.%f or something like that.
    Thanks
    float should be OK -the product is probably getting too small to print using %f, try %g which will give number with an exponent such as 1.2e-008, e.g.
    Code:
           printf("product %g\n", product);

    Comment

    • madhankrish
      New Member
      • Dec 2006
      • 16

      #3
      wow horace!
      you are a C wizard, i say!
      it worked!
      you seem to help me out everytime..
      thanks so much

      madhankrish

      Comment

      Working...