Sign in to follow this  
n4gix

String Formatting

Recommended Posts

I need to swprintf mach speed like this: .87 MHere is the swprintf line:swprintf(mach_wch, L"%0.2f M", mach_speed);How can I eliminate the leading 0 and have only the decimal value displayed?

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

((A:Autopilot mach hold var,mach) 100 *)%.%!02.0f! is what you want I believe. This is XML, but I think you get the drift.Mitch

Share this post


Link to post
Share on other sites

How aboutint iMach;iMach = (int)(mach_speed * 100);swprintf(mach_wch, L".%2d M", iMach);Doug

Share this post


Link to post
Share on other sites

>How about>>int iMach;>iMach = (int)(mach_speed * 100);>swprintf(mach_wch, L".%2d M", iMach);Thanks to both you and Mitch (with his XML example)...I had already tried a variation on this, but when I got a "kernel32.dll error," I erroneously thought it due to the L".%2d M", syntax. What my real error was is that I was trying to do the "math" in the swprintf() function itself... *:-* :~P :-bang This works fine now: UINT32 imach_speed = 0; MODULE_VAR mvmach = {MACH}; case PANEL_SERVICE_PRE_UPDATE: lookup_var (&mvmach); imach_speed = (FS_MACH(mvmach.var_value.n))*100; case PANEL_SERVICE_PRE_DRAW: /* MACH Digital Display */ WCHAR mach_wch[10] = L""; swprintf(mach_wch, L".%02d M", imach_speed); RectF rectFmach(0.0f, -1.0f, 68.0f, 26.0f); stringFormat.SetAlignment(StringAlignmentNear); if (showmach == 1) { graphics.FillRectangle(&blackBrush, rectFmach); graphics.DrawString(mach_wch, -1, &Arial22, rectFmach, &stringFormat, &whiteBrush); }http://forums.avsim.net/user_files/139884.jpg

Share this post


Link to post
Share on other sites

yeah, using a %f specifier would not allow it.If a period is specified there's always one digit printed before the period. Unless no number follows the period in which case there's no period printed but the value is rounded.Regards.Ernie.

Share this post


Link to post
Share on other sites

Bill,It struck me, after I posted, that you will need to trap the possibility of the aircraft exceeding Mach 1. The existing code (as well as my example) will display that as ".100 M" rather than "1.00 M"Doug

Share this post


Link to post
Share on other sites

>Bill,>>It struck me, after I posted, that you will need to trap the>possibility of the aircraft exceeding Mach 1. The existing>code (as well as my example) will display that as ".100 M">rather than "1.00 M"Doug, if the Citation XLS exceeds Mach 1, I should think the last thing they'll worry about is whether the display is correct... ;)Top speed is 0.87 M.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this