String.Format tips

Format a number in different ways:

// Result is rounded to 1.9, 2.0, 2.1, etc.
string snitt = String.Format("{0:.0}",total / antal);

// Fill unused space with zeroes
// 000, 001, ..., 023, ... 122, ..., 1232
string s = String.Format("{0:000}", i);

// Result is rounded to 0, 1, 2, etc.
avtal.TimpottReguljar.TimmarKvar.ToString("0");

// Right-justified text
string s = String.Format("{0,3}", i);

// Separation into 3 digit groups ("323 232"):
string s = amount.ToString("### ### ###").Trim();

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.