Hi there,
I've written a program that calculates the average of a few things. How ever somtimes the average can be say for for example 69.3%. If I was to get that value to show, would I use a float or a double?
I've tried using a float but it would only display the value as 69 and not the full value?
Not quite sure how to go about this?
Any suggestions would be appreciated!
Many thanks
Matt Seymour
monkeyhead
0
Newbie Poster
Recommended Answers
Jump to Postpost your code. It doesn't matter whether it is a float or double -- the problem is not the data type but how you are trying to display it. If this is a C program and you are using printf(), then the format string needs to be "%.1f", not "%d".
Jump to PostI don't see the line that is displaying the average, but I suspect the problem may be here:
>>average=grand_total/x;
since grand_total and x are both integers the vaue of average will also be an integer. typecase the two integers to float and the compiler will use floating point math, …
All 6 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
monkeyhead
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
monkeyhead
0
Newbie Poster
ndeniche
402
Posting Virtuoso
Featured Poster
ndeniche
402
Posting Virtuoso
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.