formatter

Java String.format() with HALF_EVEN rounding

情到浓时终转凉″ 提交于 2019-12-24 02:17:15
问题 I'd like to use String.format() to format some BigDecimals as part of a string: // Example: String getPrice( String pattern ) { BigDecimal price = basePrice.multiply( BigDecimal.ONE.add( vatRate ) ); BigDecimal priceInPence = price.multiply( new BigDecimal( "100" ) ); BigDecimal annualPrice = price.multiply( new BigDecimal( "365" ) ); return String.format( pattern, priceInPence, annualPrice ); } String myPrice1 = getPrice( "Your price is %1$.3fp/day (£2$.2f/year) including VAT" ); // -->

How to register formatters in Spring MVC web application?

霸气de小男生 提交于 2019-12-24 01:56:30
问题 I am facing the problem while binding nested object in Model Attribute. I have one class Book, in which I have nested class Subject as below : @Entity @Table(name = "book") public class Book { // Other properties... // With all getter setter.. @ManyToOne @JoinColumn(name="subject_id",nullable=false) @NotBlank(message = "Please select subject") private Subject subject; // Getter setter of subject; } Also I have implemented Formatter class for Subject as below : @Component public class

Zend Studio formatter uses wrong format

╄→гoц情女王★ 提交于 2019-12-24 00:46:24
问题 I am using ibuildings ZF. When I press Ctr+Shift+F the code is formated this way $adapter = $this->getAuthAdapter( $form->getValues()); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if (! $result->isValid()) { $form->setDescription( 'Invalid credentials provided'); $this->view->form = $form; return $this->render('index'); } but I want to be formatted that way $adapter = $this->getAuthAdapter($form->getValues()); $auth = Zend_Auth::getInstance(); $result = $auth-

String.format using a exception.getMessage() as a format

喜你入骨 提交于 2019-12-23 17:35:15
问题 I have a question related to String.format in JAVA. My HibernateDao Class is responsible for persisting entities and will throw an exception in case I have any constrain violation. The message contains a %s and will be used as a format in the upper layers, as I should be worried about types in this layer, thus can't identify what object I could not persist. public Entity persistEntity(Entity entity) { if (entity == null || StringUtils.isBlank(entity.getId())) throw new InternalError(CANNOT

How can I format a float in Java with a given number of digits after the decimal point?

拜拜、爱过 提交于 2019-12-23 12:37:44
问题 What is the best way in Java to get a string out of a float, that contains only X digits after the dot? 回答1: Here are two ways of dealing with the problem. public static void main(String[] args) { final float myfloat = 1F / 3F; //Using String.format 5 digist after the . final String fmtString = String.format("%.5f",myfloat); System.out.println(fmtString); //Same using NumberFormat final NumberFormat numFormat = NumberFormat.getNumberInstance(); numFormat.setMaximumFractionDigits(5); final

How do I manage an unmanaged Eclipse formatting profile?

半世苍凉 提交于 2019-12-23 09:19:33
问题 Our project has an "Unmanaged profile" and save-time autoformatting. I'd like to be able to modify the settings for this unmanaged profile and be able to check them back in to version control. Eclipse's help documents are quite unhelpful ("You are not allowed to change such a profile, only the creator (manager) of the profile can change it."). 回答1: Eclipse should put a .settings folder in your project dir when you have an unmanaged profile. The only way I've found to change the settings so

Formatting array initializers with Eclipse

余生颓废 提交于 2019-12-23 08:15:46
问题 Is there any way I can instruct Eclipse's formatter to put each value in an array initializer on a new line? 回答1: You can do it this way: windows/preferences/java/code style/formatter, then near the selected active profile click edit then on the "Line Wrapping" tab Choose "Expressions"->"Array initializers" Under The list choose "Wrap all elements, every element an a new line" 回答2: Go to windows/preferences/java/code style/formatter, then near the selected active profile click edit, then on

UI5: Formatter called multiple times or too soon from an XML view

一世执手 提交于 2019-12-23 00:51:20
问题 I'm using OpenUI5. Using the formatter.js , I have formatted some text in my view. But my formatter is called 3 times: When I bind the model to panel control: oPanel.setModel(oModel, "data"); both sBirthday and sFormat are undefined . After onInit() is finished and the view is rendered: sBirthday is valorized correctly and sFormat is undefined Again: both sBirthday and sFormat ara valorized correctly. Why does this happen? Is it correct? The app get an error, because the ageDescription() in

Cocoa NSNumberFormatterCurrencyStyle without “$” return zero

你说的曾经没有我的故事 提交于 2019-12-22 10:33:30
问题 I have a number formatter set up to convert currency strings to decimal values. The problem is that if the text string does not have a leading dollar sign ("$"), it gets converted to 0, rather than a valid matching number. So: "$3.50" converts to 3.50 "3.50" converts to 0 Here is the code for the converter: // formatter to convert a value to and from a currency string NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init]; [currencyFormatter setNumberStyle

Eclipse Code Formatter Plugin

主宰稳场 提交于 2019-12-22 08:07:05
问题 Can some one suggest me a plugin to format HTML and JAVA code with proper indents etc ? Is there any built in option there in Eclipse ? 回答1: Eclipse does have built in Java formatting: Preferences > Java > Code Style > Formatter For HTML, you might try something like HTML Tidy. The Web Tools Platform project also includes formatting. 回答2: Use Source -> Format or CTRL+SHIFT+F 回答3: It's a combination of all the answers above, which suits me- Go to Preferences > Java > Code Style > Formatter and