number-formatting

What is the equivalent of NumberFormat in JavaScript or JQuery?

淺唱寂寞╮ 提交于 2019-11-28 07:46:54
问题 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? 回答1: Use the NumberFormatter plug-in for JQuery. FYI: the old link was here. 回答2: I know this doesn't really answers your question, but have you thought of using the jstl formatNumber tag? 回答3: Use JSTL <fmt:formatNumber> ...

Java FRANCE/FRENCH Locale thousands separator looks like space but not actually

*爱你&永不变心* 提交于 2019-11-28 07:28:08
问题 If I convert a number in FRANCE/FRENCH locale it should use space as thousands separator. If I try to replace the spaces with some other characters, it does not find any space. String input = NumberFormat.getNumberInstance(Locale.FRANCE).format(123123123); System.out.println("String after conversion in locale "+input); input = input.replace(" ", "."); System.out.println("After replace space with dot "+input); OUTPUT String after conversion in locale 123 123 123 After replace space with dot

Inconsistency with gnuplot format specifiers %t and %T?

◇◆丶佛笑我妖孽 提交于 2019-11-28 06:21:35
问题 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

java.lang.NumberFormatException: For input string: “”

烈酒焚心 提交于 2019-11-28 05:29:44
问题 When running this code: JTextField ansTxt; ... ansTxt = new JTextField(5); String aString = ansTxt.getText(); int aInt = Integer.parseInt(aString); Why do I get this error? Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" UPDATE: JTextField ansTxt; ansTxt = new JTextField(5); ansTxt.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { ansTxt = (JTextField) e.getSource(); String aString = ansTxt.getText().trim(); int aInt = Integer

Numbers with leading zeroes, using vb6

假如想象 提交于 2019-11-28 04:12:06
问题 How can I add leading zeroes to a number? For example: Dim stracctnumber as String stracctnumber = 987654321 If stracctnumber is less than 15 characters, then add leading zeroes to the account number. The final number should be stracctnumber = "000000987654321" Can anyone help me? 回答1: stracctnumber = Format(stracctnumber, String(15, "0")) 回答2: strAcct = Right("000000000000000" & strAcct, 15) Note that concatenation is relatively 'expensive'. If this is just for display, rather than modifying

How do I format a number with a variable number of digits in Python? [duplicate]

妖精的绣舞 提交于 2019-11-28 03:27:04
This question already has an answer here: Format string dynamically 5 answers Say I wanted to display the number 123 with a variable number of padded zeroes on the front. For example, if I wanted to display it in 5 digits I would have digits = 5 giving me: 00123 If I wanted to display it in 6 digits I would have digits = 6 giving: 000123 How would I do this in Python? There is a string method called zfill: >>> '12344'.zfill(10) 0000012344 It will pad the left side of the string with zeros to make the string length N (10 in this case). If you are using it in a formatted string with the format()

Make a two-digit string from a single-digit integer

狂风中的少年 提交于 2019-11-28 02:58:39
How can I have a two-digit integer in a a string, even if the integer is less than 10? [NSString stringWithFormat:@"%d", 1] //should be @"01" I believe that the stringWithFormat specifiers are the standard IEEE printf specifiers . Have you tried [NSString stringWithFormat:@"%02d", 1]; Use the format string %02d . This specifies to format an integer with a minimum field-width of 2 characters and to pad the formatted values with 0 to meet that width. See man fprintf for all the gory details of format specifiers. If you are formatting numbers for presentation to the user, though, you should

JasperReports: How to format numeric data with Excel exporter

烂漫一生 提交于 2019-11-28 01:00:14
问题 I'm using iReport 2.0.2 . I have a problem with formatting numeric data after generating report with help of Excel exporter. For example, the 85110057689 string is showing as 8.51100e+10 in Excel file (as result of using "preview in Excel" button in iReport ). Please suggest how to change the format to the simple (not scientific). 回答1: We can use net.sf.jasperreports.export.xls.detect.cell.type property for solving issue. The quote from documentation: net.sf.jasperreports.export.xls.detect

Convert cell to array in matlab

只愿长相守 提交于 2019-11-28 00:58:05
问题 I have a certain cell of size 400x1. It basically consists of numbers in the form of string. I mean when I do mycell{1} it gives result '1' So you can see the number 1 is in the form of string. How can I convert this into a numeric array? 回答1: Like this if the size(mycell) is 400x1 . . . . . str2num(cell2mat(mycell)) ... or like this if the size is 1x400 str2num(cell2mat(mycell')) However, this will cause problems if any of your strings contain a different number of characters, i.e. mycell{1}

How to format double value for a given locale and number of decimal places?

冷暖自知 提交于 2019-11-27 23:28:52
问题 How can I use NumberFormat to format a double value for a given Locale (default locale is sufficient) and for a given number of decimal places? For example, I have these values: double d1 = 123456.78; double d2 = 567890; And I want to print them in the following way, for example with US locale and 2 decimal places: 123,456.78 567,890.00 I don't actually care about rounding mode in this case, because these double values are gained from a BigDecimal with the given scale, so their number of