number-formatting

How to Round Decimals to 2 Places after the Decimal Point (Java)

左心房为你撑大大i 提交于 2019-12-01 09:42:56
问题 I am fairly new to java and I have to create this program to which I have no idea where to start. Can someone please help me with what to do and how to write the code to get started? Write a program that will emulate a cash register. Prompt the user to input the price of three items. Add them together to get a subtotal. Determine the tax (6% ) on the subtotal. Find the total amount of the sale subtotal plus tax. Display the price of each item, subtotal amount, tax amount and final amount. So

JFormattedTextField to format percent numbers?

放肆的年华 提交于 2019-12-01 08:46:58
问题 I would like to format a float number as a percent-value with JFormattedTextField that allows inputs from 0 to 100 percent (converted to 0.0f-1.0f), always shows the percent sign and disallows any invalid characters. Now I have experimented a bit with NumberFormat.getPercentInstance() and the NumberFormatter attributes but without success. Is there a way to create a JFormattedTextField that obeys to these rules with the standard classes? Or do I have to implement my own NumberFormatter? That

How to make JFormattedTextField accept integer without decimal point (comma)?

与世无争的帅哥 提交于 2019-12-01 08:39:24
I used JFormattedTextField with NumberFormat in this way: -Creat a JFormattedTextField refernce JFormattedTextField integerField; -Create a NumberFormat refernce NumberFormat integerFieldFormatter; -In the constructor: integerFieldFormatter = NumberFormat.getIntegerInstance(); integerFieldFormatter.setMaximumFractionDigits(0); integerField = new JFormattedTextField(integerFieldFormatter ); integerField.setColumns(5); .......... I meant to use it with integer numbers only, but when I type numbers like 1500 it is converted after losing focus to 1,500 , and exception thrown this is the first line

setlocale to fr-FR in PHP and number formatting

风格不统一 提交于 2019-12-01 07:41:27
I am trying to create a French version of one of my sites. I have set setlocale(LC_ALL, 'fr_FR'); at the top of my page, and using strftime I am displaying dates correctly in the French style. However I am having some problems with a number. Part of the page uses data I am getting from a Web Service. I am assigning a returned value to a var like this: $overallRating = $returnArray['Overall']; I am then using the following code later to format it to 1 decimal place number_format($overallRating,1) In the English version the overallRating value might be 7.5 and returns a value such as 7.5 (the

How to make JFormattedTextField accept integer without decimal point (comma)?

≯℡__Kan透↙ 提交于 2019-12-01 07:17:00
问题 I used JFormattedTextField with NumberFormat in this way: -Creat a JFormattedTextField refernce JFormattedTextField integerField; -Create a NumberFormat refernce NumberFormat integerFieldFormatter; -In the constructor: integerFieldFormatter = NumberFormat.getIntegerInstance(); integerFieldFormatter.setMaximumFractionDigits(0); integerField = new JFormattedTextField(integerFieldFormatter ); integerField.setColumns(5); .......... I meant to use it with integer numbers only, but when I type

Format a cell as arbitrary currency regardless of locale, using VBA

 ̄綄美尐妖づ 提交于 2019-12-01 06:59:30
This is really bugging me as it seems pretty illogical the way it's working. I have a macro to format a cell as a currency using a bit of code to obtain the currency symbol. Here is the code involved: Dim sym As String sym = reportConstants(ISOcode) 'Just use the ISO code if there isn't a symbol available If sym = "" Then sym = ISOcode End If With range(.Offset(0, 3), .Offset(3, 3)) .NumberFormat = sym & "#,##0;(" & sym & "#,##0)" Debug.Print sym & "#,##0;(" & sym & "#,##0)" End With reportConstants is a dictionary object with currency symbols defined as strings. E.g. reportConstants("USD") =

How to customize number format in freemarker?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 06:31:23
I am using freemarker and trying to display numbers in this format: $3,343,434.00 for example. This was easily taken care of by using ${total?string.currency} (assuming "total" is some number). However, when I have negative numbers, it's showing them like this: ($343.34) instead of this: -$343.34 . I need the negative sign instead of the parenthesis. Is there a way I could customize the formatting so it does everything that the string.currency did but replace the negative value behavior? I am relatively new to freemarker, so detailed responses are appreciated! You can also try ?string(",##0.00

Use Different Locale for @NumberFormat in Spring

泪湿孤枕 提交于 2019-12-01 06:05:33
I am working on a Spring 3 project and I need to format a Long field for Turkish currency. The default Locale of the application is en_US . I used the @NumberFormat annotation as below: @NumberFormat(style=NumberFormat.Style.CURRENCY) public Long getBudgetLimit() { return budgetLimit; } The annotation works and formats the form field in English locale. However I need to use Turkish locale for this field. Is there a way to set the locale of a single field or a page different than the application's locale? Edit : I just found the answer myself. Use a custom editor in the controller as below:

How to customize number format in freemarker?

谁都会走 提交于 2019-12-01 05:52:11
问题 I am using freemarker and trying to display numbers in this format: $3,343,434.00 for example. This was easily taken care of by using ${total?string.currency} (assuming "total" is some number). However, when I have negative numbers, it's showing them like this: ($343.34) instead of this: -$343.34 . I need the negative sign instead of the parenthesis. Is there a way I could customize the formatting so it does everything that the string.currency did but replace the negative value behavior? I am

Format a cell as arbitrary currency regardless of locale, using VBA

a 夏天 提交于 2019-12-01 05:04:33
问题 This is really bugging me as it seems pretty illogical the way it's working. I have a macro to format a cell as a currency using a bit of code to obtain the currency symbol. Here is the code involved: Dim sym As String sym = reportConstants(ISOcode) 'Just use the ISO code if there isn't a symbol available If sym = "" Then sym = ISOcode End If With range(.Offset(0, 3), .Offset(3, 3)) .NumberFormat = sym & "#,##0;(" & sym & "#,##0)" Debug.Print sym & "#,##0;(" & sym & "#,##0)" End With