January 23, 200620 yr Moderator 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? Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
January 24, 200620 yr Author Moderator bump Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
January 24, 200620 yr ((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
January 24, 200620 yr How aboutint iMach;iMach = (int)(mach_speed * 100);swprintf(mach_wch, L".%2d M", iMach);Doug
January 24, 200620 yr Author Moderator >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 Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
January 24, 200620 yr 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.
January 24, 200620 yr 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
January 25, 200620 yr Author Moderator >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. Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
Create an account or sign in to comment