Re: Converting double to widestring
* Alex Blekhman:
"Alf P. Steinbach" wrote:
And given that, I'd prefer to suggest using the internal
function that swprintf uses, namely _cfltcvt, which is just a
macro that in turn references the first function pointer in
array _cfltcvt_tab.
Why not to use perfectly available and documented
_fcvt/_ecvt/_gcvt functions? Also, it seems that these functions
aren't affected by locale settings.
Indeed. I was thinking of avoiding conversion to wchar_t. I was looking at
those functions first but dimissed them since they're char based and so started
delving into internals, but hey, _cfltcvt is also char-based; it's swprintf that
converts the result, and does that rather inefficiently for this case...
However, I'm now looking at them again, and _ecvt and _fcvt use a statically
allocated buffer, which may be a little unthread-safe (not that I thought of
that earlier, at least as far as I can recall). And _gcvt, where you can
specify the buffer, doesn't have a precision argument (OP requires to be able to
specify "how many decimal places to be used"), but a total number of digits.
This essentially means having to call it twice for each number.
If using these functions I think I'd take my chances with _ecvt and/or _fcvt,
since they have precision arguments, but that would require much testing for
multi-threading.
Cheers, & thanks,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?