number-formatting

How to pass a decimal value from JSP to Action with a Localized decimal separator?

拜拜、爱过 提交于 2019-12-04 14:54:46
In the JSP: <input type = "number" name = "score" min = "0" max = "100" maxlength = "3" step = "0.01" /> In the Action: @Getter @Setter private Float score; When the value has decimal places (eg. 56,78 ), in the Action I get 5678.0 . This is due to the fact that Struts2 is not aware that in my country , is the decimal separator, not the thousands separator. Is there a way to instruct Struts2 to use the decimal separator of a specific Locale , so that it will be able to convert the floating numbers correctly ? When the value has decimal places (eg. 56,78), in the Action I get 5678.0 This is

How to comma-separate numbers in EditText

非 Y 不嫁゛ 提交于 2019-12-04 14:33:56
I have an EditText that has an inputType of number . While the user is typing, I want to comma-separate the numbers. Here's a little illustration: 123 would be represented as 123 1234 would be represented as 1,234 12345 would be represented as 12,345 ...and so on. I tried adding a comma with TextWatcher as shown below: EditText edittext = findViewById(R.id.cashGiven); edittext.addTextChangedListener(new TextWatcher(){ @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2

Arbitrary Currency String - Get all parts separated?

狂风中的少年 提交于 2019-12-04 12:27:56
I have arbitrary String with currencies like 100,00€ or $100.00 or 100.00USD (arbitrary lenght, any valid Currency on earth both Symbol and ISO-Code )...(=like 100.000.000,00 EUR ). There is no guarantee that the currencies are correct, it might be an invalid Symbol or Character or at the wrong position (after or before the number)... What is the easiest way to get: The integer part The decimal part The Currency (if valid) I know of NumberFormat/CurrencyFormat but this class is only usefull if you know the exact locale in advance and seems to be working only to correctly formatted string...

Converting a decimal to a hexadecimal number

亡梦爱人 提交于 2019-12-04 11:48:52
Why we use + 55 for converting decimal to hex num . in this code we use +48 to convert integer to character . when temp < 10 . But when temp > =10 we use +55 . what does it mean by +55 ? #include<stdio.h> int main(){ long int decimalNumber,remainder,quotient; int i=1,j,temp; char hexadecimalNumber[100]; printf("Enter any decimal number: "); scanf("%ld",&decimalNumber); quotient = decimalNumber; while(quotient!=0){ temp = quotient % 16; //To convert integer into character if( temp < 10) temp =temp + 48; else temp = temp + 55; hexadecimalNumber[i++]= temp; quotient = quotient / 16; } printf(

J2ME - number format

╄→尐↘猪︶ㄣ 提交于 2019-12-04 11:41:38
I need to format decimal numbers with patterns in J2ME just like java DecimalFormat . I see an option to port Format / NumberFormat / DecimalFormat . Can you suggest ready to use implementation or library? Thanks! So, I've manage to port desktop java implementation: bbnumberformat : String[] patterns = new String[] { "#,#00.00#", "0.0;(0.0)", "0.###E0" }; DecimalFormat format = (DecimalFormat) DecimalFormat .getNumberInstance(); double value = -12.321; for (int i = 0; i < patterns.length; i++) { String pattern = patterns[i]; format.applyPattern(pattern); String text = "Pattern: " + pattern + "

How to parse numbers more strict than what NumberFormat does in Java?

冷暖自知 提交于 2019-12-04 10:53:45
问题 I'm validating user input from a form. I parse the input with NumberFormat, but it is evil and allow almost anything. Is there any way to parse number more strict? E.g. I would like to not allow these three inputs, for an integer, but Numberformat allow all of them: NumberFormat nf = NumberFormat.getNumberInstance(); nf.setParseIntegerOnly(true); Number numberA = nf.parse("99.731"); // 99 (not what the user expect) Number numberB = nf.parse("99s.231"); // 99 (invalid) Number numberC = nf

Localized exponential notation?

六眼飞鱼酱① 提交于 2019-12-04 09:30:59
问题 i'm trying to convert numbers into localized strings. For integers and money values it's pretty simple, since the string is just a series of digits and digit grouping separators. E.g.: 12 345 678 901 (Bulgarian) 12.345.678.901 (Catalan) 12,345,678,901 (English) 12,34,56,78,901 (Hindi) 12.345.678.901 (Frisian) 12?345?678?901 (Pashto) 12'345'678'901 (German) i use the Windows GetNumberFormat function to format integers (and GetCurrencyFormat to format money values). But some numbers cannot be

Numbers in the form of 001

浪子不回头ぞ 提交于 2019-12-04 07:32:17
Is there a special name for numbers in the format of 001. For example the number 20 would be 020 and 1 would be 001. Its hard to Google around when you don`t know somethings name! Since I am already wasting your guys time does any one know a function for changing numbers to this format. I think this is usually called "padding" the number. Its called left zero padded numbers. It's called padding . Well, if you're talking about that notation within the context of certain programming languages, 020 as opposed to 20 would be Octal rather than Decimal. Otherwise, you're referring to padding. A

Mathematica internal number formats and precision

一曲冷凌霜 提交于 2019-12-04 07:15:41
Tangentially related to this question, what exactly is happening here with the number formatting? In[1] := InputForm @ 3.12987*10^-270 Out[1] := 3.12987`*^-270 In[2] := InputForm @ 3.12987*10^-271 Out[2] := 3.1298700000000003`*^-271 If you use *10.^ as the multiplier the transition is where you would naively expect it to be: In[3] := InputForm @ 3.12987*10.^-16 Out[3] := 3.12987`*^-16 In[4] := InputForm @ 3.12987*10.^-17 Out[4] := 3.1298700000000004`*^-17 whereas *^ takes the transition a bit further, albeit it is the machine precision that starts flaking out: In[5] := InputForm @ 3.12987*^

Masking numbers in PrimeFaces footerText column Datatable

戏子无情 提交于 2019-12-04 06:05:56
I want to display a masked number like this: 1.234.567,89. The following code already do this: <p:column> <h:outputText value="#{item.value}"> <f:convertNumber locale="pt_BR"/> </h:outputText> </p:column> How can I applly the same mask for a Primefaces datatable in a footerText column as the following code excerpt? <p:columnGroup type="footer"> <p:row> <p:column colspan="8" footerText="Grand Total:" /> <p:column footerText="#{upbController.totalLosses}" /> </p:row> </p:columnGroup> Thanks in advance. You can try to place your footerText using f:facet . Here is how I used to use it for p:column