Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

c# - print double with digits after decimal point

How can I customize a function in which I print doubles? I would like this function to get number of digits after the decimal point (comma in my locale) as an agrument and then print, for example, pi with the number of digits after comma specified by user.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var digits = 4;
var myDouble = Math.PI;

var formattedValue = myDouble.ToString("N" + digits.ToString(),
    CultureInfo.CurrentCulture);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...