Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Formatting Question

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
0
0
US
_sDMSPacket = string.Format(":000000 {0:0000}{1}{2:0000} {3:0000}\r\n", (int)Math.Floor(dHeave * 100 + 0.5), 'G', (int)Math.Floor(dRoll * _R2D * 100 + 0.5), (int)Math.Floor(dPitch * _R2D * 100 + 0.5));


Using the above, I get values like

:000000 -0021G0006 0281
:000000 -0018G0028 0285

and it should look like:
:000000 -0021G 0006 0281
:000000 -0018G 0028 0285

There will be times when the value will be negative and should look like:

:000000 -0021G-0006 0281
:000000 -0018G-0028 0285

and currently my formatting forks for that but when the value is positive, I seem to not be able to keep the space.

I would appreciate any ideas or help.

Thanks

fergmj


 
If I put the space in there, it will be there for the negative numbers also and the numbers will be formatted like:

:000000 -0021G -0006 0281
:000000 -0018G -0028 0285
instead of

:000000 -0021G-0006 0281
:000000 -0018G-0028 0285
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top