number-formatting

Double to string conversion without scientific notation

[亡魂溺海] 提交于 2019-11-26 01:29:46
问题 How to convert a double into a floating-point string representation without scientific notation in the .NET Framework? \"Small\" samples (effective numbers may be of any size, such as 1.5E200 or 1e-200 ) : 3248971234698200000000000000000000000000000000 0.00000000000000000000000000000000000023897356978234562 None of the standard number formats are like this, and a custom format also doesn\'t seem to allow having an open number of digits after the decimal separator. This is not a duplicate of

How do I format a number in Java?

ε祈祈猫儿з 提交于 2019-11-26 01:21:07
问题 How do I format a number in Java? What are the \"Best Practices\"? Will I need to round a number before I format it? 32.302342342342343 => 32.30 .7323 => 0.73 etc. 回答1: From this thread, there are different ways to do this: double r = 5.1234; System.out.println(r); // r is 5.1234 int decimalPlaces = 2; BigDecimal bd = new BigDecimal(r); // setScale is immutable bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); r = bd.doubleValue(); System.out.println(r); // r is 5.12 f = (float)

How can I format a String number to have commas and round?

有些话、适合烂在心里 提交于 2019-11-26 01:06:52
问题 What is the best way to format the following number that is given to me as a String? String number = \"1000500000.574\" //assume my value will always be a String I want this to be a String with the value: 1,000,500,000.57 How can I format it as such? 回答1: You might want to look at the DecimalFormat class; it supports different locales (eg: in some countries that would get formatted as 1.000.500.000,57 instead). You also need to convert that string into a number, this can be done with: double

Format / Suppress Scientific Notation from Python Pandas Aggregation Results

被刻印的时光 ゝ 提交于 2019-11-26 00:40:53
问题 How can one modify the format for the output from a groupby operation in pandas that produces scientific notation for very large numbers? I know how to do string formatting in python but I\'m at a loss when it comes to applying it here. df1.groupby(\'dept\')[\'data1\'].sum() dept value1 1.192433e+08 value2 1.293066e+08 value3 1.077142e+08 This suppresses the scientific notation if I convert to string but now I\'m just wondering how to string format and add decimals. sum_sales_dept.astype(str)

Using String Format to show decimal up to 2 places or simple integer

隐身守侯 提交于 2019-11-26 00:36:38
问题 I have got a price field to display which sometimes can be either 100 or 100.99 or 100.9, What I want is to display the price in 2 decimal places only if the decimals are entered for that price , for instance if its 100 so it should only show 100 not 100.00 and if the price is 100.2 it should display 100.20 similarly for 100.22 should be same . I googled and came across some examples but they didn\'t match exactly what i wanted : // just two decimal places String.Format(\"{0:0.00}\", 123.4567

How to format a floating number to fixed width in Python

天涯浪子 提交于 2019-11-26 00:31:38
问题 How do I format a floating number to a fixed width with the following requirements: Leading zero if n < 1 Add trailing decimal zero(s) to fill up fixed width Truncate decimal digits past fixed width Align all decimal points For example: % formatter something like \'{:06}\' numbers = [23.23, 0.123334987, 1, 4.223, 9887.2] for number in numbers: print formatter.format(number) The output would be like 23.2300 0.1233 1.0000 4.2230 9887.2000 回答1: for x in numbers: print "{:10.4f}".format(x) prints

Force R not to use exponential notation (e.g. e+10)?

微笑、不失礼 提交于 2019-11-26 00:23:49
问题 Can I force R to use regular numbers instead of using the e+10 -like notation? I have: 1.810032e+09 # and 4 within the same vector and want to see: 1810032000 # and 4 I am creating output for an old fashioned program and I have to write a text file using cat . That works fine so far but I simply can\'t use the e+10 notation there. 回答1: This is a bit of a grey area. You need to recall that R will always invoke a print method, and these print methods listen to some options. Including 'scipen' -

PowerShell, formatting values in another culture

旧巷老猫 提交于 2019-11-25 22:52:47
Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses . as a decimal separator, while PowerShell honors my locale settings ( de-DE ) when converting floating-point numbers to strings. Is there an easy way to set another locale for a function or so without sticking .ToString((New-Object Globalization.CultureInfo "")) after every double variable? Note: This is about the locale used for formatting, not the format string. (Side question: Should I use the invariant culture in that case or

C# convert int to string with padding zeros?

感情迁移 提交于 2019-11-25 22:48:29
问题 In C# I have an integer value which need to be convereted to string but it needs to add zeros before: For Example: int i = 1; When I convert it to string it needs to become 0001 I need to know the syntax in C#. 回答1: i.ToString().PadLeft(4, '0') - okay, but doesn't work for negative numbers i.ToString("0000"); - explicit form i.ToString("D4"); - short form format specifier 回答2: i.ToString("D4"); See MSDN on format specifiers. 回答3: Here's a good example: int number = 1; //D4 = pad with 0000

How to output numbers with leading zeros in JavaScript [duplicate]

邮差的信 提交于 2019-11-25 22:28:31
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I create a Zerofilled value using JavaScript? I can round to x amount of decimal places with math.round but is there a way to round left of the decimal? for example 5 becomes 05 if I specify 2 places 回答1: NOTE : Potentially outdated. ECMAScript 2017 includes String.prototype.padStart You're asking for zero padding? Not really rounding. You'll have to convert it to a string since numbers don't make sense