-4

hi m showing some value in jquery and just wants to reduce it,

value showing:

  6.333333333333333

I just wants that it shows like this:

  6.3

how to do this because google is not showing more results about it

dev
  • 3
  • 5

1 Answers1

0

Use round method:

var myNum = 6.333333333333333;
var rounded = Math.round( myNum * 10 ) / 10;
console.log(rounded);
Bilal Siddiqui
  • 3,579
  • 1
  • 13
  • 20
  • 3
    or `Number(number.toFixed(1))` - the `Number()` being optional if you want the result to be a Number rather than a string – Bravo Oct 07 '19 at 08:23
  • now nthing is showing maybe mistake in code: { sortable: false, data: function (data) { var rounded = Math.round( number * 10 ) / 10; // code to show ang rating at tab 4 return data.avgRating; } }, – dev Oct 07 '19 at 08:27
  • did you replaced `number` with your original variable ? – Bilal Siddiqui Oct 07 '19 at 08:30
  • I replaced but nthing is happening – dev Oct 07 '19 at 08:34
  • { sortable: false, data: function (data) { var rounded = Math.round( data.avgRating * 10 ) / 10; // code to show ang rating at tab 4 return data.avgRating; } }, – dev Oct 07 '19 at 08:34
  • data.avgRating = Math.round( data.avgRating * 10 ) / 10 – Bilal Siddiqui Oct 07 '19 at 08:36