www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - wsprintf with floats

reply "Steve & Denise De Chellis" <dbouton snet.net> writes:
How do I use wsprintf with a float? I tried %f but it just printed f

If i use %i it cuts off the decimal...

Steve De Chellis
Jul 03 2002
next sibling parent reply "Walter" <walter digitalmars.com> writes:
%g for floats, %d for integers. -Walter

"Steve & Denise De Chellis" <dbouton snet.net> wrote in message
news:afvcvu$26q7$1 digitaldaemon.com...
 How do I use wsprintf with a float? I tried %f but it just printed f

 If i use %i it cuts off the decimal...

 Steve De Chellis
Jul 03 2002
parent reply "Steve & Denise De Chellis" <dbouton snet.net> writes:
          wsprintf (szBuffer, TEXT ("c %g "), fEncumb);
          SetDlgItemText (hDlg, 28, szBuffer);

That is the code I tried but in the Dialog I end up with "c g"

Steve


"Walter" <walter digitalmars.com> wrote in message
news:afvo5v$2hge$1 digitaldaemon.com...
 %g for floats, %d for integers. -Walter

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:afvcvu$26q7$1 digitaldaemon.com...
 How do I use wsprintf with a float? I tried %f but it just printed f

 If i use %i it cuts off the decimal...

 Steve De Chellis
Jul 03 2002
parent reply "Steve & Denise De Chellis" <dbouton snet.net> writes:
Changing it to sprintf did work though....

Anyone know why?

Steve De Chellis

"Steve & Denise De Chellis" <dbouton snet.net> wrote in message
news:ag0auc$25p$1 digitaldaemon.com...
           wsprintf (szBuffer, TEXT ("c %g "), fEncumb);
           SetDlgItemText (hDlg, 28, szBuffer);

 That is the code I tried but in the Dialog I end up with "c g"

 Steve


 "Walter" <walter digitalmars.com> wrote in message
 news:afvo5v$2hge$1 digitaldaemon.com...
 %g for floats, %d for integers. -Walter

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:afvcvu$26q7$1 digitaldaemon.com...
 How do I use wsprintf with a float? I tried %f but it just printed f

 If i use %i it cuts off the decimal...

 Steve De Chellis
Jul 03 2002
parent reply "Walter" <walter digitalmars.com> writes:
Try replacing TEXT("c %g") with L"c %g".

"Steve & Denise De Chellis" <dbouton snet.net> wrote in message
news:ag0isj$aq9$1 digitaldaemon.com...
 Changing it to sprintf did work though....

 Anyone know why?

 Steve De Chellis

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:ag0auc$25p$1 digitaldaemon.com...
           wsprintf (szBuffer, TEXT ("c %g "), fEncumb);
           SetDlgItemText (hDlg, 28, szBuffer);

 That is the code I tried but in the Dialog I end up with "c g"

 Steve


 "Walter" <walter digitalmars.com> wrote in message
 news:afvo5v$2hge$1 digitaldaemon.com...
 %g for floats, %d for integers. -Walter

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:afvcvu$26q7$1 digitaldaemon.com...
 How do I use wsprintf with a float? I tried %f but it just printed f

 If i use %i it cuts off the decimal...

 Steve De Chellis
Jul 03 2002
parent reply "Matthew Wilson" <matthew thedjournal.com> writes:
Guys

Maybe I've missed something all these years, but I never thought that
wsprintf handled floating point. The help for wsprintf certainly does not
mention any floating point format sequences.

Matthew

"Walter" <walter digitalmars.com> wrote in message
news:ag0k94$bu6$1 digitaldaemon.com...
 Try replacing TEXT("c %g") with L"c %g".

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:ag0isj$aq9$1 digitaldaemon.com...
 Changing it to sprintf did work though....

 Anyone know why?

 Steve De Chellis

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:ag0auc$25p$1 digitaldaemon.com...
           wsprintf (szBuffer, TEXT ("c %g "), fEncumb);
           SetDlgItemText (hDlg, 28, szBuffer);

 That is the code I tried but in the Dialog I end up with "c g"

 Steve


 "Walter" <walter digitalmars.com> wrote in message
 news:afvo5v$2hge$1 digitaldaemon.com...
 %g for floats, %d for integers. -Walter

 "Steve & Denise De Chellis" <dbouton snet.net> wrote in message
 news:afvcvu$26q7$1 digitaldaemon.com...
 How do I use wsprintf with a float? I tried %f but it just printed
f
 If i use %i it cuts off the decimal...

 Steve De Chellis
Jul 03 2002
parent reply "Walter" <walter digitalmars.com> writes:
It should work just like sprintf, but for wchar's.

"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:ag0lbp$d39$1 digitaldaemon.com...
 Guys

 Maybe I've missed something all these years, but I never thought that
 wsprintf handled floating point. The help for wsprintf certainly does not
 mention any floating point format sequences.

 Matthew
Jul 04 2002
parent reply "Matthew Wilson" <matthew thedjournal.com> writes:
Walter,

No offense, but I think you're getting mixed up with swprintf - the wide
version of sprintf - which is an ANSI function. Steve is talking (as am I)
about wsprintf - the USER32 sprintf replacement (apart from floating
points) - which is a shorthand for all those people (wise souls, at least
when using MSVC) who do not wish to link to the C-runtime libaries. Neither
the ANSI (wsprintfA) or Unicode (wsprintfW) versions use floating points,
I'm afraid

Matthew

"Walter" <walter digitalmars.com> wrote in message
news:ag0vqq$o8r$1 digitaldaemon.com...
 It should work just like sprintf, but for wchar's.

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:ag0lbp$d39$1 digitaldaemon.com...
 Guys

 Maybe I've missed something all these years, but I never thought that
 wsprintf handled floating point. The help for wsprintf certainly does
not
 mention any floating point format sequences.

 Matthew
Jul 05 2002
parent reply "Walter" <walter digitalmars.com> writes:
Oh, I think you're right. My goof! I always have to stop and think if it's
sw or ws. Argh.

"Matthew Wilson" <matthew thedjournal.com> wrote in message
news:ag3g4m$5dc$1 digitaldaemon.com...
 Walter,

 No offense, but I think you're getting mixed up with swprintf - the wide
 version of sprintf - which is an ANSI function. Steve is talking (as am I)
 about wsprintf - the USER32 sprintf replacement (apart from floating
 points) - which is a shorthand for all those people (wise souls, at least
 when using MSVC) who do not wish to link to the C-runtime libaries.
Neither
 the ANSI (wsprintfA) or Unicode (wsprintfW) versions use floating points,
 I'm afraid

 Matthew
Jul 05 2002
parent "Matthew Wilson" <matthew thedjournal.com> writes:
No worries. I guess I'm more attuned only because I chronically spend so
much effort in avoiding M$'s C-runtime library ...

"Walter" <walter digitalmars.com> wrote in message
news:ag4kcs$1bdq$2 digitaldaemon.com...
 Oh, I think you're right. My goof! I always have to stop and think if it's
 sw or ws. Argh.

 "Matthew Wilson" <matthew thedjournal.com> wrote in message
 news:ag3g4m$5dc$1 digitaldaemon.com...
 Walter,

 No offense, but I think you're getting mixed up with swprintf - the wide
 version of sprintf - which is an ANSI function. Steve is talking (as am
I)
 about wsprintf - the USER32 sprintf replacement (apart from floating
 points) - which is a shorthand for all those people (wise souls, at
least
 when using MSVC) who do not wish to link to the C-runtime libaries.
Neither
 the ANSI (wsprintfA) or Unicode (wsprintfW) versions use floating
points,
 I'm afraid

 Matthew
Jul 09 2002
prev sibling parent reply mindstorm <mindstorm_member pathlink.com> writes:
In article <afvcvu$26q7$1 digitaldaemon.com>, Steve & Denise De Chellis says...
How do I use wsprintf with a float? I tried %f but it just printed f

If i use %i it cuts off the decimal...

Steve De Chellis
I don't know who's still listening here, but after finding this paste via a google link, I later worked out a solution. So wsprintf() doesn't support floating point numbers at all. Just do "wsprintf(yourBuffer, "%d.%d", (int)smallvalue, (int)(smallvalue/1000));", it works too. Thought I'd share that tip. Mindstorm www.mindstormgames.com
May 08 2006
parent asdfsa <johnelway hotmail.com> writes:
This forum is dead, but thanks for the tip.
Feb 14 2007