number-formatting

How to control number of decimal digits in write.table() output?

混江龙づ霸主 提交于 2019-11-30 01:10:51
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, 'clipboard', sep='\t',row.names=F) The digits parameter is ignored and numbers are not rounded. See nice output > ttf.all year V1.x.x V1.y.x ratio1 V1.x.y V1.y.y ratioR V1.x.x V1.y.x ratioAL V1.x.y V1.y.y ratioRL 1 2006 227 645 35.2 67 645 10.4 150 645 23.3 53 645 8.22 2 2007 639 1645 38.8 292 1645 17.8 384 1645 23.3 137 1645 8.33 3 2008 1531 3150 48.6 982 3150

Add comma to numbers every three digits in datatable (R)

旧街凉风 提交于 2019-11-29 19:21:00
问题 Suppose my data looks like this: df1 = data.frame(A=c(1000000.51,5000.33), B=c(0.565,0.794)) I want to use DataTables and have column A be (1,000,001 ; 5,000) library(DT) datatable(df1) %>% formatPercentage('B', 2) %>% formatRound('A',digits = 0) I know i can use scales library(scales) comma_format()(1000000) but I'm not sure how to combine that with DataTables Thanks! 回答1: Had this same issue: Try This: require(DT) require(dplyr) df1 = data.frame(A=c(1000000.51,5000.33, 2500, 251), B=c(0.565

PHP number_format is rounding?

浪子不回头ぞ 提交于 2019-11-29 18:26:38
问题 I have a price "0,10" or "00000,10" Now when i try number_format($price, 2, ',', '') I get 0,00. How can i fix this? I want 0,10 $. I don't want rounding. Or when i have 5,678, i get 5,68. But i want 5,67. 回答1: You can increase the size of the number before rounding down with floor: $price = floor($price * 100) / 100; $formatted = number_format($price, 2, ',', ''); Another solution, which may give better precision since it avoids floating-point arithmetic, is to format it with three decimals

Printing the digits of a number in reverse order

徘徊边缘 提交于 2019-11-29 18:15:14
Can someone please help me solve this? The number should be variable and not constant. The output should be: Timestamping In 6 Digit 8 5 6 3 0 1 Average In 6 Digit 9 8 7 6 5 2 class Timestamp1 extends Average1 { public static void main (String args[]) { int i = 103658; int j = 10; int k = i % j; System.out.println(" Timestamping In 6 Digit " ); System.out.println(" " + k); int o = 10365; int p = 10; int q = o % p; System.out.println(" " + q); int l = 1036; int m = 10; int n = l % m; System.out.println(" " + n); int r = 103; int s = 10; int t = r % s; System.out.println(" " + t); int u = 10;

How to set tooltips to display percentages to match axis in Google Visualization Line Chart?

安稳与你 提交于 2019-11-29 17:32:42
问题 The tooltips can be set to display percentages using the following code: var formatter = new google.visualization.NumberFormat({ fractionDigits: 2, suffix: '%' }); formatter.format(data, 1); // Apply formatter to first column. Is there a way for NumberFormat to multiply each element by 100? Otherwise the tooltip appears as .50%. I am using vAxis.format = "format:'#%' " which does multiply by 100. So .5 is displayed as 50% on the vertical axis. According to the documentation(icu-project.org

How to turn a float number like 293.4662543 into 293.47 in python?

邮差的信 提交于 2019-11-29 16:28:17
问题 How to shorten the float result I got? I only need 2 digits after the dot. Sorry I really don't know how to explain this better in English... Thanks 回答1: From The Floating-Point Guide's Python cheat sheet: "%.2f" % 1.2399 # returns "1.24" "%.3f" % 1.2399 # returns "1.240" "%.2f" % 1.2 # returns "1.20" Using round() is the wrong thing to do, because floats are binary fractions which cannot represent decimal digits accurately. If you need to do calculations with decimal digits, use the Decimal

Use comma instead of dot for decimals when saving as text

家住魔仙堡 提交于 2019-11-29 15:31:44
This question looks similar to Visual basic handle decimal comma , but that one is about an entirely different problem. I am writing a VBA macro to save my Excel file to a .txt file. This code line was generated by actually recording a macro where I saved the file to .txt : ActiveWorkbook.SaveAs Filename, FileFormat:=xlText Now, the issue is that the .txt file has all decimals formatted with dots, while I require them to be commas. For instance, it writes 32.7 while I am expecting 32,7 . Some interesting details: I have made sure that Windows and Excel are setup to use the correct local

How to get the pattern of Number Format of a specific locale?

末鹿安然 提交于 2019-11-29 15:29:45
I have a simple question: How to get the pattern used to format a number using NumberFormat created for a specific locale as shown below: import java.util.Locale; Locale aLocale = new Locale("fr","CA"); NumberFormat numberFormat=NumberFormat.getNumberInstance(aLocale); Here I want to know the pattern used to format a number in French language and the country of Canada . For e.g. : a number 123456.7890 is converted into 123 456,789 after formatting it means pattern may be # ###,### for above mentioned locale. The subclasses DecimalFormat and ChoiceFormat have a method toPattern(), so you must

What is the equivalent of NumberFormat in JavaScript or JQuery?

痞子三分冷 提交于 2019-11-29 14:04:12
I use formatter for my double values in Java like: private static final NumberFormat formatter = new DecimalFormat("###0.00"); formatter.format(doubleValue); However I don't want to do it on the server side. How can I write an equivalent code in Javascript or JQuery? Use the NumberFormatter plug-in for JQuery. FYI: the old link was here . I know this doesn't really answers your question, but have you thought of using the jstl formatNumber tag? Use JSTL <fmt:formatNumber> ... http://www.tutorialspoint.com/jsp/jstl_format_formatnumber_tag.htm <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp

Inconsistency with gnuplot format specifiers %t and %T?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 12:15:14
If you use the gnuplot format specifiers %t and %T , you will observe some inconsistent behaviour. ### gnuplot format specifiers Numbers = "94 95 99 100 101" do for [n in Numbers] { print gprintf("%3g",n)." = ".gprintf("%t",n)." x 10^".gprintf("%T",n) } Mantissa(n) = real(n)/10**floor(log10(n)) Power(n) = floor(log10(n)) do for [n in Numbers] { print gprintf("%3g",n)." = ",Mantissa(n)," x 10^",Power(n) } ### end of code Result: 94 = 9.400000 x 10^1 95 = 0.950000 x 10^2 99 = 0.990000 x 10^2 100 = 1.000000 x 10^2 101 = 1.010000 x 10^2 94 = 9.4 x 10^1 95 = 9.5 x 10^1 99 = 9.9 x 10^1 100 = 1.0 x