decimal-point

convert decimal mark

試著忘記壹切 提交于 2019-11-26 16:34:21
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 ? eumiro float("2,5".replace(',', '.')) will do in most cases If value is a large number and . has been used for thousands, you can: Replace all commas for points: value.replace(",", ".") Remove all but the last point: value.replace(".", "", value.count(".") -1) You may do it the locale-aware way: import locale # Set to users preferred locale: locale.setlocale(locale

Javascript: formatting a rounded number to N decimals

江枫思渺然 提交于 2019-11-26 10:21:47
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 * Math.pow(10, dec)) / Math.pow(10, dec); } console.log(roundNumber(0.1 + 0.2, 2)); console.log(roundNumber(2.1234, 2)); 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 rounded to "2". Any ideas? That's not a rounding ploblem, that is a display problem. A number

Leave only two decimal places after the dot

我怕爱的太早我们不能终老 提交于 2019-11-26 09:09:41
问题 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) { label4.Text = \"Server is currently offline.\"; } } Currently my label4.Text get\'s something like: \"187.371698712637\". I need it to show something like: \"187.37\" Only two posts after the DOT. Can someone help me out? 回答1: string.Format is your friend.

What is the decimal separator symbol in JavaScript?

☆樱花仙子☆ 提交于 2019-11-26 08:14:22
问题 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 separator symbol. Ultimately I\'d like to write code that supports both decimal points in user input - culture-specific and . , but I can\'t write such a code

Change decimal separator in MySQL

杀马特。学长 韩版系。学妹 提交于 2019-11-26 05:37:44
问题 Is it possible to change the decimal comma from \".\" (dot) to other character (comma) in MySQL output? I don\'t want to use functions like FORMAT , I just want to use all the queries I normaly use without any modification. I\'m looking for some setting (of some variable, locale etc.). I tried to search the manual but without success. 回答1: No, you can't. That's the SQL standard and MySQL complies with it (in that point at least). The problem is not really with output (as you mention, there

Javascript: formatting a rounded number to N decimals

杀马特。学长 韩版系。学妹 提交于 2019-11-26 01:58:23
问题 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 * Math.pow(10, dec)) / Math.pow(10, dec); } console.log(roundNumber(0.1 + 0.2, 2)); console.log(roundNumber(2.1234, 2)); 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\

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

醉酒当歌 提交于 2019-11-26 00:47:30
问题 Can I do it with System.out.print ? 回答1: You can use the printf method, like so: System.out.printf("%.2f", val); In short, the %.2f syntax tells Java to return your variable ( val ) with 2 decimal places ( .2 ) in decimal representation of a floating-point number ( f ) from the start of the format specifier ( % ). There are other conversion characters you can use besides f : d : decimal integer o : octal integer e : floating-point in scientific notation 回答2: You can use DecimalFormat. One way

Round to at most 2 decimal places (only if necessary)

蹲街弑〆低调 提交于 2019-11-25 22:55:14
问题 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? 回答1: Use Math.round(num * 100) / 100 回答2: If the value is a text type: parseFloat("123.456").toFixed(2); If the value is a number: var numb = 123.23454; numb = numb.toFixed(2); There is a downside that values like 1.5 will give "1.50" as the output. A fix suggested by @minitech: var numb = 1.5; numb = +numb.toFixed(2); // Note the plus sign that

Formatting a number with exactly two decimals in JavaScript

拟墨画扇 提交于 2019-11-25 21:43:23
问题 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 want numbers like 10.80, 2.40, etc. Use of jQuery is fine with me. 回答1: To format a number using fixed-point notation, you can simply use the toFixed method: (10.8).toFixed(2); // "10.80" var num = 2.4; alert(num.toFixed(2)); // "2.40" Note that