how can a make the floating variable show just 4 digits i mean : 8.6540098 to just 8.654 i guess what i'm trying to say is "less decimals" :D
apo 0 Newbie Poster
Recommended Answers
Jump to PostUse the proper format specifier in a printf statement:
printf("%.4f", myFloatVar);
This will display 4 positions past the decimal. See printf doc for more details.
Jump to PostYou then use:
printf("%4.3f", myFloatVar);
But note that if the value in "myFloatVar" has 2 digits left of the decimal, you'll get those two, along with the 3 past the decimal.
All 11 Replies
mcriscolo 47 Posting Whiz in Training
apo 0 Newbie Poster
mcriscolo 47 Posting Whiz in Training
some 0 Newbie Poster
mrnutty 761 Senior Poster
apo 0 Newbie Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
apo 0 Newbie Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
apo 0 Newbie Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague 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.