I have the results of a division and I wish to discard the decimal portion of the resultant number.

How can I do this?

You could use `Math.floor()`

(round down), `Math.ceil()`

(round up) or `Math.round()`

(round to nearest integer), dependent on how you wanted to remove the decimal.

If you simply want to truncate the decimal portion, use a bitwise operator (.e.g `|0`

) which will treat its operand as a signed 32bit integer.

You may also be talking about the inaccuracy of decimal rounding with floating point arithmetic.

Use `Math.round()`

.

(Alex's answer is better; I made an assumption :)

You could also do

```
parseInt(a/b)
```

Use `Math.round()`

function in jquery.

```
Math.round(65.98) // will return 66
Math.round(65.28) // will return 65
```

*I think that you should use `Math.round(number)`

For example, if you want to make a program that gets the square root of a number from input: public static void main(String[] args){

```
Scanner input = new Scanner(System.in);
System.out.println("Type in number you wish to be solved.");
System.out.println(Math.round(Math.sqrt(input.nextInt())));
}
```

So say we typed in `169`

as an input, if you just used `Math.sqrt(number)`

it would return `13.0`

.

But if you used it with `Math.round(number)`

, it would return `13`

. Now if you wanted it to round up or down (if not perfect square) you would use the following: `Math.ceil(number)`

To round upwards. And `Math.floor(number)`

to round downwards.*

u can also show a certain number of digit after decimal point(hear 2 digit) using following code :

```
var num = 15.46974
num = num.toFixed(2)
```

toFixed will behave like round.

For a floor like behavior use %:

```
var num = 3.834234;
var floored_num = num - (num % 1); // floored_num will be 3
```

With ES2015, Math.trunc() is available.

```
Math.trunc(2.3) // 2
Math.trunc(-2.3) // -2
Math.trunc(22222222222222222222222.3) // 2.2222222222222223e+22
Math.trunc("2.3") // 2
Math.trunc("two") // NaN
Math.trunc(NaN) // NaN
```

It's not supported in IE11 or below, but does work in Edge and every other modern browser.

Similar Questions

I need a regular expression that validates a number, but doesn't require a digit after the decimal. ie. 123 123. 123.4 would all be valid 123.. would be invalid Any would be greatly appreciated!

I want to remove a specific function which is void (doesn't return anything) from my javascript source code using php at run time. Consider the following js code which is supposed to be outputted by p

I want to remove following javascript from html file. <script src=text/javascript> alert('hello'); })(); </script> and <script src=text/javascript> alert('hello'); } catch(err) {}

Possible Duplicate: How do I format a double to currency rounded to the nearst dollar? How can i remove decimal from a currency? Here is how I format a number to currency: string.Format({0:C}, Amo

I have the following code which gives me result: 4.00 USD <?php echo $number->currency($auction['Product']['rrp'], $appConfigurations['currency']); ?> I want to remove decimal. Result shoul

How to convert this 20,00 into 2000 in javascript ? Basically how to remove decimal sign but keep all digits?

I need a function which takes a calculated value (can range from very small to very large) and rounds it to a number of decimal places for display. The number of decimal places should depend on the ma

var height = $(#divOne).height(); How to remove first number from height variable? for example if height of this element is 118 I want to be 18.

Possible Duplicate: Elegant workaround for JavaScript floating point number problem Why is it that when adding 2 numbers together using javascript, it will return a crazy number of decimal points? I

I wanted to display a number to 2 decimal places. I thought I could use toPrecision(2) in JavaScript . However, if the number is 0.05, I get 0.0500. I'd rather it stay the same. See it on JSbin. What

I need to show the value 29.89 like this. but not need to show like that 29.0, If after whole number is start with 0 means we need not show. Example: 27.0 ==> 27 only 27.9 ==> 27.9 this is wrigh

There's any way to format an input[type='number'] value to always show 2 decimal places? Example: I want to see 0.00 instead of 0. Thanks

This question already has an answer here: Remove property from JavaScript object 9 answers I have object and I need to remove entry from object depends on user selection. So I have made an fidd

How do you remove a breakpoint from Safari 4's Javascript debugger?

How do I go about writing a function to convert a decimal number string to a decimal and a decimal number to a string?

What I am trying to do is to create a small Chrome extension that will automatically trim the &bar= parameter from a list of links So a link such as: http://www.website.com/page&foo=2&bar=

I try to convert decimal prime number to binary format... I've got 2 different working code blocks but I don't how to integrated with them. Here's my prime number code: #include <stdio.h> #inclu

When a User accidentally enters two more more decimal points, I want to only use the Right Most decimal point. So: 1234..55 would equal 1234.55 It's easy to make typos, but I have not seen any good c

In this web i see that all answer about thins like converting decimal number to binary its refers number without point in the number(int)... i want to know how to convert the decimal number with point

I have a column that just has 4 numbers and I want to remove the first. I Run a update query I found on here but it says no columns affected. UPDATE mytable SET mycol = TRIM(LEADING '[0-9]' FROM myc

I have a column named streetaddress that contains <Street Number> <Street Name> for example: 15 rue Gontier-Patin 4968 Hillcrest Circle how can i remove the numbers from the beginning of

I have a variable of decimal type and I want to check the number of digits before decimal point in it. What should I do? For example, 467.45 should return 3.

Here's the scenario: I'm getting .9999999999999999 when I should be getting 1.0. I can afford to lose a decimal place of precision, so I'm using .toFixed(15), which kind of works. The rounding works,

What is the maximum number of digits we can have after the decimal point of a BigDecimal value in Java?

I have to convert floating point number from binary to usable decimal number. Of course my floating point number has been separated into bytes, so 4 bytes total. 1 2 3 4 [xxxxxxxx][xxxxxxxx][xxxxxxxx]

I wanna remove decimal number on Y axis in achartengine graph library as shown below : CODE : public GraphicalView createIntent(List<double[]> values, float height_) { height_ = (float) (height

I want to validate a field in javascript to have at least 1 and should be positive number or decimal. Examples: 1 1.1 0.1 10.10 My current regex looks like this: var _RegEx = /^[+]?([0-9]+(?:[\.][0-9

I'm trying to write a function that will remove a query argument from a url in javascript. I think I have it using regex, but I'm not sure if I've missed anything. Also, I can't shake the feeling that

Is there a Java library to remove lines based on line number? My aim is to remove lines based on line numbers. Example Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac tu

I am trying to remove just the decimal point from a decimal number in c#? For ex: My decimal number is 2353.61 I want 235361 as the result. My decimal number is 196.06 I want 19606as the result. How c

I can't seem to find the function to remove a shape or path from the canvas after it has been created. So I'm creating a bezier curve between 2 points with beginPath(); bezierCurveTo(); stroke(); clos

I have a lot of numbers to deal with from my UI. I want some of them to be no decimal places, some to be 2 decimals, and others to be however they are entered (3 or 4 decimal places). I have a convert

I don't know how to convert a non terminating binary number(fraction) to decimal . Can anybody guide me how to do with an example?

I want to remove the numbers, decimal present after number (no after character) using Regax. example: let i have a string name abc4.5,asdjh44400.555 and dasqw123123. then the output should be abc,asdj

I need to check if a number entered contain 1.more than two digit after decimal 2.decimal at first place (ex:.2345) 3.decimal at last place (ex:2345.) How to do this using javascript.

how to format number with . as thousand separator, and , as decimal separator in MySql? I'm using Format function like SELECT Format(myNumber,2) as myNumberFormatted FROM ... But return type is

I wrote a function to remove odd number from a list, like that: def remove_odd(l): for i in l: if i % 2 != 0: l.remove(i) print l return l remove_odd([4,5,4]) remove_odd([4,5,4,7,9,11]) remove_odd([4,

I'm displaying a Number from a plist in one of my labels (if key exists). If i typed in 98,90 in the plist it sometimes changed the number to i.e 98,9000000000001. So I want to display the numbers wit

I'm looking for C# regular expression to replace/remove all JavaScript from HTML. Can someone please help me with the code?

values = [8160,8160,6160,22684,0,0,60720,1380,1380,57128] how can I remove outliers like 0, 57218, 60720 and 22684? Is there a library which can do this?

When I use the python Decimal object simply with something like: from decimal import * dec = Decimal('3.432') print dec it will print 3.432, just like I want, but if i try to put that same value dec

I have this page table below and I want to remove the numbering prefix of '999' from the column of template_id, page_id template_id url 1 9991 a 2 9992 b 3 9993 c 4 4 d so I can get the updated data

I have a table which has a DECIMAL(4,2) column. It has values like 1.0, 1.1, 1.2, 2.0, 3.0, 3.1. How can I retrieve values that are only whole numbers? I am doing SELECT * FROM table WHERE field LIKE

If you declare a numeric vector with a mix of decimal and integer values and print it, all of them are converted to a decimal number. s <- c(0, 1.1, 2, 3) print(s) [1] 0.0 1.1 2.0 3.0 but if you u

In Javascript, one of the reliable ways to convert a string to a number is the Number constructor: var x = Number('09'); // 9, because it defaults to decimal Inspired by this question, I started wond

Using JSONObject to read a json response from a server. The server returns some decimal number. Normal numbers are not a problem to but the problem occurs when there is decimal number of form 0.00068.

I have these very simple 3 lines of code which, to my understanding, should allow the user to enter a decimal number and then spit the number out. System.out.print(Enter a number.\n); double numbe

I am having this query which show the output as numer number SELECT rlseamt FROM ln01mast WHERE acno=214 I want to convert it to decimal amount for two digits ex:198.00

I know about 'strtoll' but that is converting any Radix Base Number (between 2 and 36) to Decimal and I need to do the opposite by converting Decimal to Any Radix Base Number, an example would be dec

I have the following code snippet (Not self written, obtained from Add a list item through javascript) Demo of relevant Script here: http://jsfiddle.net/Gmyag/ The HTML Portion: First name: <input