decimal-point

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? ...

In Perl, how can I limit the number of places after the decimal point but have no trailing zeroes?

This question is similar to "dropping trailing ‘.0’ from floats", but for Perl and with a maximum number of digits after the decimal. I'm looking for a way to convert numbers to string format, dropping any redundant '0', including not just right after the decimal. And still with a maximum number of digital, e.g. 3 The input data is fl...

How to format a decimal

Using C#, I want to format a decimal to only display two decimal places and then I will take that decimal and subtract it to another decimal. I would like to be able to do this without having to turn it into a string first to format and then convert it back to a decimal. I'm sorry I forget to specify this but I don't want to round, I jus...

How do you calculate floating point in a radix other than 10?

Given Wikipedia's article on Radix Point, how would one calculate the binary equivalent of 10.1 or the hex equivalent of 17.17? For the former, what is the binary equivalent of a tenth? For the latter, the hex representation of 17/100? I'm looking more for an algorithm than for solutions to just those two examples. ...

double string conversion and locale

A common international issue is the conversion of double values represented in strings. These stuff is found in a lot of areas. Starting with csv files which are either called comma separated or character separated because sometimes they are stored like 1.2,3.4 5.6,6.4 in English regions or 1,2;3,4 5,6;6,4 in for example Ger...

What's the best technique for handling US Dollar calculations in Perl?

What's the best technique for handling US Dollar calculations in Perl? Especially: the following needs to work: $balance = 10; $payment = $balance / 3; # Each payment should be 3.33. How best to round amount? $balance -= $payment * 3; # assert: $balance == .01 ...

General programming - Decimal numbers, floats

I'm probably completely wrong, and I don't really know anything about it, but I have a question about decimal number data types in programming languages. I understand that floats aren't completely precise, because they're stored in binary with a power or something, but I always wondered why decimal number data types don't just store a nu...

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"); } catch (Exception) { ...

JavaScript: Rounding to two decimal places. Not less than two

Hello all, I have this line of code which rounds my numbers to 2 decimal places. But the thing is I get numbers like this. 10.8, 2.4 etc. These are not my idea of 2 decimal places so how I can improve this: Math.round(price*Math.pow(10,2))/Math.pow(10,2); I want numbers like 10.80, 2.40 etc. Use of JQuery is fine with me. Thanks for...

How to properly display a price up to two decimals (cents) including trailing zeros in Java?

There is a good question on rounding decimals in Java here. But I was wondering how can I include the trailing zeros to display prices in my program like: $1.50, $1.00 The simple solution of String.format("%.2g%n", 0.912385); works just fine, but omits the trailing zero if it is at the last decimal place. The issue comes up in my pro...

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 I'm processing a user input, it's likely to include the local culture-specific decimal separ...

round number in JavaScript to N decimal places

in JavaScript, the typical way to round a number to N decimal places is something like: function round_number(num, dec) { return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); } However this approach will round to a maximum of N decimal places while I want to always round to N decimal places. For example "2.0" would be r...

In Java, why does the decimal separator follow the Locale's language, not its country, and, more importantly, how does one override it?

Hello, I'm working on an international project and have observed that, in Java, the choice of the decimal separator is based on the Locale's language, not its country. For example: DecimalFormat currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("it","IT")); System.out.println(currencyFormatter.format(-123456.78));...

Using AJAX Control Toolkits NumericUpDown Control with Comma as Decimal Separator

We are trying to use the NumericUpDown Control from the AJAX Control Toolkit, but can find no way to make it use a comma as a decimal separator instead of a point. Other controls such as the Calendar will automatically use the Page Culture and adapt their content according to it. Do anyone know a way to change the Decimal Separator? ...

limit double at six decimal place in asp.net

hi, i have a double, the decimal place isn't fix (8-?) i want to fix the decimal place to six (for example: 1,234567). this is my double: CStr(score) i guess it's quiet simple :P ...

How to display an output of float data with 2 decimal places in Java?

Can I do it with System.out.print? Thank you. ...

Why did the digit grouping and decimal separator change for en-ZA from .NET 3.5 to .NET 4.0?

We have code in our system to format numbers and currency according to the regional settings selected by the user. One of our users has selected en-ZA and noticed that the digit grouping and decimal separators have changed with our migration to .NET 4.0. I wrote a snippet of code to illustrate this change: using System; namespace regio...

Magento - decimal points in invoice/be

hi, I need for my shop up to 4 decimal points. So far I followed some tuts and theyre working fine in front & backend for products. Only in sales/invoice prices,tax and totals are still rounded to 2 decimal points. I've edited/overwrote following files: \app\code\local\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php s...

How do I set the correct decimal separator in IIS 6.0?

Hello everybody, I hope you can help me here... I have a conflict with the decimal separator on my host's dedicated server. The DB (SQL SERVER 2005) uses dot as decimal separator. As a fact, if you query it directly using SQL Server Management you would get dots. However, when the application (.NET C# MVC 2) is running it uses comma inst...