Apr 12, 2003 #1 davman2002 Programmer Joined Nov 4, 2002 Messages 75 Location US is there a way to format a double? for example Can I format 95.8586321465 as 98.96
Apr 14, 2003 #2 psemianonymous Programmer Joined Dec 2, 2002 Messages 1,877 Location US If you're using printf, you can do: Code: printf("%2.2f",dblDouble) ; and this will *guarantee* you two digit IN FRONT of the decimal and two digits BEHIND. This prints to standard output. For using something like cout<<, you can set the parameters by using the "ios::setf()" function. Link: http://www.cplusplus.com/ref/iostream/ios_base/setf.html Later, Peter -- Find common answers using Google Groups: http://groups.google.com/groups?group=comp.databases.ms-access Corrupt MDBs FAQ http://www.granite.ab.ca/access/corruptmdbs.htm Upvote 0 Downvote
If you're using printf, you can do: Code: printf("%2.2f",dblDouble) ; and this will *guarantee* you two digit IN FRONT of the decimal and two digits BEHIND. This prints to standard output. For using something like cout<<, you can set the parameters by using the "ios::setf()" function. Link: http://www.cplusplus.com/ref/iostream/ios_base/setf.html Later, Peter -- Find common answers using Google Groups: http://groups.google.com/groups?group=comp.databases.ms-access Corrupt MDBs FAQ http://www.granite.ab.ca/access/corruptmdbs.htm
Apr 20, 2003 #3 butthead Programmer Joined Feb 24, 2002 Messages 545 Location US char dblstr [50]; double y = 48538509731.957587020283475983; strcpy (dblstr, FloatToStr .c_str ()); for (unsigned int x = 0; x < strlen (dblstr); x++) { if (dblstr [x] == '.') { x = x + 3; dblstr [x] = NULL; } } Edit1->Text = dblstr; It could use some help for the proper rounding of the last digit. tomcruz.net Upvote 0 Downvote
char dblstr [50]; double y = 48538509731.957587020283475983; strcpy (dblstr, FloatToStr .c_str ()); for (unsigned int x = 0; x < strlen (dblstr); x++) { if (dblstr [x] == '.') { x = x + 3; dblstr [x] = NULL; } } Edit1->Text = dblstr; It could use some help for the proper rounding of the last digit. tomcruz.net