-8

I want to round off the given number to one decimal place but if the number is a whole number then output should have one zero after decimal.
Example:

Input: 24.66, 24.0002, 24.62

Output : 24.7, 24.0, 24.6

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • 6
    Did you really not Google this, before posting this question ? This question has been asked hundreds of times before, and there's plenty of examples out there, eg : http://stackoverflow.com/questions/12146100/string-format-for-only-one-decimal-place – Mike Gledhill Aug 10 '15 at 11:06
  • 1
    In C#? Or with jQuery (which is a *JavaScript* library)? You've tagged both, which doesn't make a lot of sense. – T.J. Crowder Aug 10 '15 at 11:07
  • @Backs - Without knowing which the OP is using, we can't know which tag to remove. OP Please read [ask] – Sayse Aug 10 '15 at 11:13

1 Answers1

1

Try this

var value = 24.66;
var result = Math.Round(value, 1);
NASSER
  • 5,900
  • 7
  • 38
  • 57