number-formatting

JTable cell editor number format

喜夏-厌秋 提交于 2019-11-27 23:12:06
I need to show numbers in jTable with exact 2 decimal places. To accomplish this I have created a custom cell editor as: public class NumberCellEditor extends DefaultCellEditor { public NumberCellEditor(){ super(new JFormattedTextField()); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JFormattedTextField editor = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value!=null){ DecimalFormat numberFormat = new DecimalFormat("#,##0.00;(#,##0.00)"); editor.setFormatterFactory

f:convertNumber remove comma as thousand separator [duplicate]

核能气质少年 提交于 2019-11-27 22:38:26
This question already has an answer here: Set decimal separator when using f:convertNumber 1 answer I want to round value with four decimal places to one decimal place. That is why I use f:convertNumber : <h:outputText value="${current.dayAverage.pressureRelative}" > <f:convertNumber maxFractionDigits="1"/> </h:outputText> The rounding is done right, but the f:convertNumber adds thousand comma separator. I want to remove this separator but I don't know how. I am using Apache MyFaces 2.1 implementation. In the API for f:convertNumber it does not have any attribute to specify thousand separator.

How to prefix a positive number with plus sign in PHP

末鹿安然 提交于 2019-11-27 21:57:58
I need to design a function to return negative numbers unchanged but should add a + sign at the start of the number if its already no present. Example: Input Output ---------------- +1 +1 1 +1 -1 -1 It will get only numeric input. function formatNum($num) { # something here..perhaps a regex? } This function is going to be called several times in echo/print so the quicker the better. Update: Thank you all for the answers. I must tell the sprintf based solution is really fast. You can use regex as: function formatNum($num){ return preg_replace('/^(\d+)$/',"+$1",$num); } But I would suggest not

How to store more than 4 decimal places in an array in MATLAB

柔情痞子 提交于 2019-11-27 16:22:43
I want to store 6 decimal digits into an array, but when I store it into array it only stores up to 4 decimal digits instead of 6. How can I store up to 6 digits into an array? For example, if e=0.059995; W(l,i)=e; but W(l,i) gives me the result as 4 decimal places disp(W(l,i)) 0.0600 How can I store 6 decimal digits into an array, i.e when I print the array it prints 6 decimal places? disp(W(l,i)) 0.059995 Can anyone help me? Vuwox Matlab on default settings stores up to 15 digits. It only your display format. Have a look at the format command. Or just type at the Matlab command prompt:

number_format() causes error “A non well formed numeric value encountered”

守給你的承諾、 提交于 2019-11-27 16:01:52
I am using number_format to round floats to only 2 decimal digits. The problem is that some of my inputs don't have more than 2 decimals digits to begin with. So the code: number_format($value, 2) Instead of peacefully adding 0 in case it doesn't have enough decimal digits, it raises errors inside Apache log and that's not desirable. So number_format(2.1, 2) or number_format(0, 2) will raise error in Apache log. [Thu Jun 30 17:18:04 2011] [error] [client 127.0.0.1] PHP Notice: A non well formed numeric value encountered in /home/tahoang/Desktop/Projects/weatherData/weatherData.php on line 41

Using Struts2 Tags to Formatting Numbers

China☆狼群 提交于 2019-11-27 15:18:35
I want to format some numbers in our jsp pages. first i define some resources in my porperties format.number.with2Decimal={0,number,#0.00} ...... Question1: i want to know what is the ‘#’ and '0' means? 0.00,#0.00,##.00,###0.00 who can tell me the differences between them? thanks! Question2: if i define a BigDecimal type in my action BigDecimal number1; Then my page should using a format to show this value, 1.if number1=null then show -NIL- 2.if number1=0 then show -NIL- 3.if number1>0 then show 1.00,3434.98 ..... please ignore number<0 Question3: change number1 to a String, 1.if number1=null

how to split the string into string and integer in java

佐手、 提交于 2019-11-27 14:59:53
问题 I have the String a="abcd1234" and i want to split this into String b="abcd" and Int c=1234 This Split code should apply for all king of input like ab123456 and acff432 and so on. How to split this kind of Strings. Is it possible? 回答1: You could try to split on a regular expression like (?<=\D)(?=\d) . Try this one: String str = "abcd1234"; String[] part = str.split("(?<=\\D)(?=\\d)"); System.out.println(part[0]); System.out.println(part[1]); will output abcd 1234 You might parse the digit

How to make Python format floats with certain amount of significant digits?

有些话、适合烂在心里 提交于 2019-11-27 14:43:15
问题 I want my Python (2.4.3) output numbers to have a certain format. Specifically, if the number is a terminating decimal with <= 6 significant digits, show it all. However, if it has > 6 significant digits, then output only 6 significant digits. "A" shows how Python is writing the floats. "B" shows how I want them written. How can I make Python format my numbers in that way? A: 10188469102.605597 5.5657188485 3.539 22.1522612479 0 15.9638450858 0.284024 7.58096703786 24.3469152383 B: 1.01885e

Formatting numbers read from spreadsheet

て烟熏妆下的殇ゞ 提交于 2019-11-27 13:59:52
问题 I'm writing a script that creates fixed-width-text output of the contents of a Google Apps Spreadsheet. I retrieve all the values of the current range using the range.getValues() method, then I loop through everything a couple times and generate a block of text that looks like a nicely-formatted table when pasted into a fixed-width-font email. The only issue I'm having is that I cannot replicate the number formatting. I can get the number formatting string using range.getNumberFormats() , but

What is the default Precision and Scale for a Number in Oracle?

会有一股神秘感。 提交于 2019-11-27 12:58:43
When creating a column of type NUMBER in Oracle, you have the option of not specifying a precision or scale. What do these default do if you don't specify them? NUMBER (precision, scale) If a precision is not specified, the column stores values as given. If no scale is specified, the scale is zero. A lot more info at: http://download.oracle.com/docs/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832 The NUMBER type can be specified in different styles : Resulting Resulting Precision Specification Precision Scale Check Comment ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――