javascript - Get the number and round to whole number -


i'm getting miles google map api v3 , displaying in textbox based on , addresses. want parse out number , round off nearest whole number.

miles = "29.9 mi" // want result 30 miles = "9.3 mi" // 10

i tried math.round it's returning nan.

if (status == google.maps.directionsstatus.ok) {         directionsdisplay.setdirections(response);         var miles = response.routes[0].legs[0].distance.text;         miles = math.round(miles);         $('#totalmiles').val(miles);     } 

try parsefloat + math.ceil:

var number = "9.3 mi"; console.log(math.ceil(parsefloat(number))); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -