The character or glyph used to separate the integer part from the fraction part in a decimal number. Usually either a dot or a comma.
Questions tagged [decimal-point]
378 questions
3220
votes
80 answers
How to round to at most 2 decimal places, if necessary?
I'd like to round at most 2 decimal places, but only if necessary.
Input:
10
1.7777777
9.1
Output:
10
1.78
9.1
How can I do this in JavaScript?
![](../../users/profiles/360705.webp)
stinkycheeseman
- 34,999
- 7
- 27
- 49
604
votes
31 answers
Formatting a number with exactly two decimals in JavaScript
I have this line of code which rounds my numbers to two decimal places. But I get numbers like this: 10.8, 2.4, etc. These are not my idea of two decimal places so how I can improve the following?
Math.round(price*Math.pow(10,2))/Math.pow(10,2);
I…
![](../../users/profiles/51649.webp)
Abs
- 51,038
- 92
- 260
- 394
216
votes
8 answers
How to change the decimal separator of DecimalFormat from comma to dot/point?
I have this little crazy method that converts BigDecimal values into nice and readable Strings.
private String formatBigDecimal(BigDecimal bd){
DecimalFormat df = new DecimalFormat();
df.setMinimumFractionDigits(3);
…
![](../../users/profiles/608728.webp)
MiraFayless
- 2,223
- 3
- 14
- 8
204
votes
17 answers
How to print a float with 2 decimal places in Java?
Can I do it with System.out.print?
![](../../users/profiles/292065.webp)
via_point
- 2,193
- 3
- 15
- 9
187
votes
5 answers
Integer.valueOf() vs. Integer.parseInt()
Aside from Integer.parseInt() handling the minus sign (as documented), are there any other differences between Integer.valueOf() and Integer.parseInt()?
And since neither can parse , as a decimal thousands separator (produces NumberFormatException),…
![](../../users/profiles/869501.webp)
ateiob
- 8,618
- 10
- 40
- 55
144
votes
24 answers
Decimal separator comma (',') with numberDecimal inputType in EditText
The inputType numberDecimal in EditText uses the dot . as decimal separator. In Europe it's common to use a comma , instead. Even though my locale is set as german the decimal separator is still the .
Is there a way to get the comma as decimal…
![](../../users/profiles/458361.webp)
mseo
- 3,711
- 3
- 19
- 26
112
votes
9 answers
Javascript: formatting a rounded number to N decimals
in JavaScript, the typical way to round a number to N decimal places is something like:
function roundNumber(num, dec) {
return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}
function roundNumber(num, dec) {
return Math.round(num…
![](../../users/profiles/105066.webp)
hoju
- 24,959
- 33
- 122
- 169
80
votes
13 answers
Leave only two decimal places after the dot
public void LoadAveragePingTime()
{
try
{
PingReply pingReply = pingClass.Send("logon.chronic-domination.com");
double AveragePing = (pingReply.RoundtripTime / 1.75);
label4.Text = (AveragePing.ToString() + "ms"); …
![](../../users/profiles/112355.webp)
Sergio Tapia
- 36,466
- 70
- 175
- 253
70
votes
3 answers
In jQuery, what's the best way of formatting a number to 2 decimal places?
This is what I have right now:
$("#number").val(parseFloat($("#number").val()).toFixed(2));
It looks messy to me. I don't think I'm chaining the functions correctly. Do I have to call it for each textbox, or can I create a separate function?
![](../../users/profiles/1122.webp)
Iain Holder
- 13,731
- 10
- 61
- 84
56
votes
2 answers
How to control number of decimal digits in write.table() output?
When working with data (e.g., in data.frame) the user can control displaying digits by using
options(digits=3)
and listing the data.frame like this.
ttf.all
When the user needs to paste the data in Excell like this
write.table(ttf.all,…
![](../../users/profiles/984532.webp)
userJT
- 9,328
- 17
- 65
- 82
53
votes
3 answers
Simplest way of getting the number of decimals in a number in JavaScript
Is there a better way of figuring out the number of decimals on a number than in my example?
var nbr = 37.435.45;
var decimals = (nbr!=Math.floor(nbr))?(nbr.toString()).split('.')[1].length:0;
By better I mean faster to execute and/or using a…
![](../../users/profiles/1830104.webp)
PhilTrep
- 1,172
- 1
- 8
- 23
48
votes
3 answers
What is the decimal separator symbol in JavaScript?
A thought struck me as I was writing a piece of JavaScript code that processed some floating point values. What is the decimal point symbol in JavaScript? Is it always .? Or is it culture-specific? And what about .toFixed() and .parseFloat()? If…
![](../../users/profiles/41360.webp)
Vilx-
- 97,629
- 82
- 259
- 398
38
votes
6 answers
How to display a number with always 2 decimal points using BigDecimal?
I am using BigDecimal to get some price values. Requirement is something like this, what ever the value we fetch from database, the displayed valued should have 2 decimal points.
Eg:
fetched value is 1 - should be displayed as 1.00
fetched value…
![](../../users/profiles/1391730.webp)
user1391730
- 381
- 1
- 3
- 3
33
votes
7 answers
convert decimal mark
I have a CSV file with data reading that I want to read into Python. I get lists that contain strings like "2,5". Now doing float("2,5") does not work, because it has the wrong decimal mark.
How do I read this into Python as 2.5?
![](../../users/profiles/578640.webp)
Till B
- 1,138
- 2
- 12
- 18
31
votes
16 answers
How can I limit the number of decimal points in a UITextField?
I have a UITextField that when clicked brings up a number pad with a decimal point in the bottom left. I am trying to limit the field so that a user can only place 1 decimal mark
e.g.
2.5 OK
2..5 NOT OK
![](../../users/profiles/1282180.webp)
user1282180
- 1,093
- 3
- 11
- 18