944,111 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5562
  • C++ RSS
Nov 3rd, 2004
0

Looking for _gcvt(double,int,string)

Expand Post »
I found this neat little GUI calculator program on the net.
It uses a function called _gcvt(double val,int limit,string cBuf), which seems to be used to convert a double val to a string cBuf, with some formatting and limiting.

I replaced it with sprintf(), but the output looks rather crude to the perfectionist.

xfind.exe can find _gcvt in a few header files, but Dev C++ does not respond to it. Does anybody have some past experience with it?
Similar Threads
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 3rd, 2004
0

Re: Looking for _gcvt(double,int,string)

_gcvt is a Visual Studio function. sprintf should work fine provided you consider limit as the number of significant precision digits.

>but the output looks rather crude to the perfectionist.
How appropriately vague. Care to be more specific?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 3rd, 2004
0

Re: Looking for _gcvt(double,int,string)

Thanks for the answer!

I will use sprintf(), but need to adjust the precision digits to something sensible.

2.3 + 3.4 = 5.700000000 looks silly!

I had the notion that _gcvt might do this.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 3rd, 2004
0

Re: Looking for _gcvt(double,int,string)

>2.3 + 3.4 = 5.700000000 looks silly!
You can specify a precision with sprintf:
C++ Syntax (Toggle Plain Text)
  1. sprintf ( cBuf, "%.*f", limit, val );
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 4th, 2004
0

Re: Looking for _gcvt(double,int,string)

Quote originally posted by Narue ...
>2.3 + 3.4 = 5.700000000 looks silly!
You can specify a precision with sprintf:
C++ Syntax (Toggle Plain Text)
  1. sprintf ( cBuf, "%.*f", limit, val );
I forgot about that, thanks Narue!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Towers of Hanoi
Next Thread in C++ Forum Timeline: structures and functions woohoo!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC