Formatting to 1 Decimal place
Hi should be a pretty easy one but could someone help me display the Average in this line to one decimal place. I presume its done with math.round() but can't figure it out.
Thanks in advance
The line is:
<c:out value="${row.Average}"/>
or seeing as you are using JSTL
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
//or <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> for Tomcat5
<fmt:formatNumber value= "${row.Average}" type="number" maxFractionDigits="1" />It uses the java.text.DecimalFormat class under the hood anyway :-)
Cheers,
evnafets
Similar Messages
-
Formatting currencies and decimal places
I'm currently using NumberFormat.getCurrencyInstance() to format numbers as currency. However, one problem I'm having is that I'd like values with no cents to be formatted with no decimal places, and any values with cents to be formatted with the usual 2 decimal places. For example:
17 would be formatted as $17
17.45 would be formatted as $17.45
17.4 would be formatted as $17.40
The last one is the tricky part--I've tried formatter.setMinimumFractionDigits(0), and this works great for the first two cases. But for the last case, the number gets formatted as $17.4.
Basically my problem is I want a number to be formatted with zero or two decimal places and nothing in between. Is there an easy way to do this?
Thanks in advance.Otherwise you are likely to find that you are getting .00 due to errors from previous calculations. You are right. Adjusted it to Locale aware
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Locale;
public class SpecialCurrencyFormat extends NumberFormat {
private static final long serialVersionUID = 1L;
private final NumberFormat noDecimals;
private final NumberFormat decimals;
private final double maxDifference;
private final double factor;
public SpecialCurrencyFormat() {
this(Locale.getDefault());
public SpecialCurrencyFormat(Locale locale) {
decimals = NumberFormat.getCurrencyInstance(locale);
noDecimals = NumberFormat.getCurrencyInstance(locale);
noDecimals.setMaximumFractionDigits(0);
maxDifference = Math.pow(10, -decimals.getMaximumFractionDigits()) * .5;
factor = Math.pow(10, decimals.getMaximumFractionDigits());
@Override
public StringBuffer format(double number, StringBuffer toAppendTo,
FieldPosition pos) {
double adjustedValue = (Math.round(number * factor)) / factor;
if ((Math.abs(number - Math.round(number)) < maxDifference)) {
return noDecimals.format(adjustedValue, toAppendTo, pos);
} else {
return decimals.format(adjustedValue, toAppendTo, pos);
@Override
public StringBuffer format(long number, StringBuffer toAppendTo,
FieldPosition pos) {
return noDecimals.format(number, toAppendTo, pos);
@Override
public Number parse(String source, ParsePosition parsePosition) {
return decimals.parse(source, parsePosition);
public static void main(String[] args) {
NumberFormat nf = new SpecialCurrencyFormat(Locale.US);
double[] values = { 10000, 1000, 100, 10, 1, 10.1, 10.01, 10.001,
10.002, 10.003, 10.004, 10.005, 10.006, 10.007, 10.008, 10.009,
10.010 };
for (double value : values) {
print(nf, value);
private static void print(NumberFormat nf, double number) {
String formatted = nf.format(number);
try {
System.out.println(number + "\tas " + formatted + "\tand back "
+ nf.parse(formatted));
} catch (ParseException e) {
e.printStackTrace();
}The value adjustedValue is needed since NumberFormat doesn't seem to round the value. It just breaks.
Piet -
Decimal format to 2 decimal places ????
Hello Everyone,
I have created a web dynpro application which to display a report depending on the data given by the BAPI. But there is some issue with the numeric data returned by the BAPI.
For ex - if the BAPI returns 5.00 the value is displayed in the report as 5.
I want uniform decimal values till 2 decimal places. For example 5 shd come as 5.00, 2.1 shd come as 2.10 etc.
I searched SDN abt this, and found many threads relating to this.
I tried using decimal format, creating a simple dictinary type, but using all this what happens is the value basically changes to a string format, this implies that the value is displayed in the table as "left-aligned".
Where- as we need the decimal numeric values to be right-aligned.
Any thoughts how to achieve this.
Please correct me if I have missed out on anything.
Thanks,
SamtaHi,
From wat i understood.. u have a attribute coming from BAPI.. which you want to display with two decimal places,,
In this case.. assuming it is coming with 2 decimal places from the backend.. create a value node.. inside the node which contains the output data. set its carinality to 1..1 .. create a value attribute of type big decimal in it.. or probably string.. if there is an issue in displaying BigDecimal directly..
map this new attribute to the necessary column in the table..
BigDecimal value = new BigDecimal("the actual value in string or long").setScale(2);
assign this to the value attribute created..
(If alignment is the problem.. set the column 's textview property halign to right.. and layout as block or paragraph.. )
Regards
Bharathwaj
Message was edited by:
Bharathwaj R -
Format to 2 decimal places?
Hi, i need to display my data in 2 decimal places but now i'm getting results after some calculation (for eg. 2.336224). How can i round it off to 2.34?
I also agree with Arun and Rajesh,
When I need to specify the number of decimal points as part of an expression, e.g. ; - Tooltip series properties of a chart.
I use; -
=ROUND(Fields!Total.Value,2)
or
=FORMAT(Fields!Total.Value,"N")
I hope this helps someone.
If you have found any of my posts helpful then please vote them as helpful. Kieran Patrick Wood MCTS BI,MCC, PGD SoftDev (Open), MBCS http://www.innovativebusinessintelligence.com/ http://uk.linkedin.com/in/kieranpatrickwood -
Hi All,
i have one issue. In this QUANTITY field is there. after mapping i have to see this field with 3 decimals like for exmple
sourc field value is 325
but i want this value in target field like 325.000
kindly give me answer as early as possible
regards
PeeraMahaboob,
If your answer is yes to Paul's question, then follow the below code in UDF.
Create simple UDF ---[ Argument : InputString]
In Imports : java.text.DecimalFormat
DecimalFormat threeDec = new DecimalFormat("0.000");
threeDec.setGroupingUsed(false);
System.out.println (threeDec.format(Double.parseDouble(InputString)));
Hope it solves ur issues!!! If not reply back.
Best regards,
raj. -
Date formatting, too many decimal places for milliseconds.
Is there any cirmumstance where the SimpleDateFormat string of:
"yyyy.MM.dd HH:mm:ss.SS "
could result in some dates being output correctly with two digits for milliseconds, and others being output with three digits!Hi ,
Sorry for the delay .
x_fieldcat-scrtext_m = 'Interest Rate'.
x_fieldcat-fieldname = 'INTEREST'.
x_fieldcat-tabname = 'IT_BSID1'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-outputlen = '13'.
x_fieldcat-edit = 'X'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
l_pos = l_pos + 1.
the strcture if it_bsid1 is
DATA : BEGIN OF IT_BSID1 OCCURS 0,
INCLUDE STRUCTURE ZFTHUNDI_NO.
BUKRS TYPE BUKRS,
HUNDI_NO TYPE ZHUNDI_NO,
VBELN TYPE VBELN_VF,
KDMAT TYPE KDMAT,
KUNNR TYPE KUNNR,
NAME1 TYPE NAME1,
ORT01 TYPE ORT01,
BUDAT TYPE BUDAT,
TYPE TYPE ZTYPE,
GRN_NO TYPE MBLNR,
GRN_DATE TYPE BUDAT,
DUEDATE TYPE ZDUEDATE,
QTY TYPE FKIMG,
REC_QTY TYPE ZREC_QTY,
ACC_QTY TYPE ZACC_QTY,
REJ_QTY TYPE ZREJ_QTY,
BAL_QTY TYPE FKIMG,
PRCTR TYPE PRCTR,
DMBTR TYPE DMBTR,
WRBTR TYPE WRBTR,
TOTAL TYPE WRBTR,
FAHA_NO1 TYPE ZFAHA,
FAHA_DATE TYPE ZFAHA_DATE,
HSDATE TYPE ZHSDATE,
HRDATE TYPE ZHRDATE,
DISDATE TYPE ZDISDATE,
HBKID TYPE HBKID,
INTEREST TYPE MENGE_D, ( i ve tried it with diff data types like dmbtr etc)
W_FLAG TYPE C,
W_FLA TYPE C ,
LIGHT TYPE C,
END OF IT_BSID1. -
Suppress decimal places in OBIEE Year column prompts
Hi gurus,
I don't know its a bug or what , in our database the "Year" columns comes without any decimal places ,also in the criteria section of the report ,I have made the data format "with '0' decimal places ", but still in the column prompt in the dashboard , I am getting year value with decimal places .
Eg. 2012 coming as 2012.00 in choice list of the prompts . Can you provide me any work around? for that thanks in advance..The problem is due the data type of the column . Go to the physical layer and check the data type . It would be of 'Double' data type .. Change it to 'Int' data type. This would solve the problem . Posting it for the benefit of others who face similar issues. let me know if it helps anyone..
-Jay -
I am using Report Builder 9i. I have an horizontal bar with the values being displayed next to the bars.
The first value is 1.000, second value 58.00, third value is 533.0. How can I change the format so no decimal places are displayed.
Thanks
BrendonBut it is not working dear..... Check ma XML code
See this coding I have to remoce the decimals from this...how can i do that...plz help me....
<rw:graph id="CT_1" src="G_COMP_CODE" groups="DEPTCODE" dataValues="Department">
<!--
<?xml version="1.0" ?>
<Graph version="2.5.0.5" depthAngle="0" pieDepth="0" pieTilt="0">
<DataviewFootnote foreground="#0" background="#ffffff"/>
<DataviewSubtitle foreground="#0" background="#ffffff"/>
<DataviewTitle foreground="#0" background="#ffffff"/>
<MarkerText visible="true"/>
<O1Axis lineWidth="1"/>
<O1MajorTick visible="false" lineWidth="1"/>
<O1Title textRotation="TR_HORIZ_ROTATE_90"/>
<PieFrame fillTransparent="false"/>
<SeriesItems>
<Series id="0" color="#99ccff"/>
</SeriesItems>
<X1Axis lineWidth="1"/>
<Y1Axis lineWidth="1" axisMinAutoScaled="false" axisMinValue="0.0" axisMaxAutoScaled="false" axisMaxValue="400.0" majorTickStepAutomatic="false" majorTickStep="50.0"/>
<Y1MajorTick visible="false" lineWidth="1"/>
<Y1Title visible="true"/>
<Y2Axis lineWidth="1"/>
<Y2MajorTick visible="false" lineWidth="1"/>
</Graph>
-->
</rw:graph>
----- -
Removing Decimal Places from Graph labels
One axis on my graph is showing decimal places despiting formatting the report field to show 0 places - the graph is reading decimal places directly from the database underneath the report . Other than editing each axis label manual (or editing the original database field) does anyone know of another way I can elimate the decimal places from the graph?
That solution only works for the x-axis but not the y-axis (or the other way round, depending on whether the chart is horizontal or vertical).
The values of the y-Axis are formatted according to the default Number Formatting. If you can afford this, change the default number formatting to 0 decimal places.
Another workaround would be to create a formula. Let's say amount was your database field. Then the formula would be
ToText({AMOUNT},0)
Put that in your chart instead of the original database field.
Cheers,
Florian -
Hi
Is there any way of setting a default number of decimal places for a new column added on a deski report, so that any new column added on any report will always take this default number of decimal places?
ThanksLouise,
Within the designer module you can set the default format for any of the objects within the universe.
In the report that than will be the default format used. If you add a new column to the report the new column gets the same format as the column where you started from. So if you are in a column where the format is 3 decimal places and you insert a new column to the left or right that new column format will also have 3 decimal places.
Regards,
Harry -
Altering number of decimal places of formatted number
Using http://java.sun.com/docs/books/tutorial/i18n/format/numberFormat.html I have worked out how to format a number, almost. When I follow the example in this tutorial that shows how format a double, it always rounds it to 3 decimal places. How do I alter the number of decimal places that this formatting procedure outputs? I used the US as the locale and English as the language. I am assuming that if these parameters are chosen, 3 decimal places is the output. Is this assumption correct?
Look at the next chapter :)
http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html -
Formatting decimal places in the X Axis
I’m having trouble limiting the number of decimal places in my X Axis on a 2 Axis plot.
I am running a script file (SUD) that sets all the other parameters in the Plot. The “Report “ file is called up and then the script controls the functions.
This is only a small section of the code. I haven’t found a command to set the Decimal place in the “help” page.
ie: Call GraphObjOpen("2DAxis1_XAxis1")
D2AxisXFormat = " "
D2AxisXAng = 0
D2AxisXRelPos = "bottom"
D2AxisXFont = ""
D2AxisXSize = 2
D2AxisXColor = "blue"
D2AxisXColorRGB = 50266112
D2AxisXAutoColor = 0
D2AxisXBold = 0
D2AxisXItal = 0
D2AxisXUndl = 0
D2AxisXStrOut = 0
D2AxisXFrame = 0
Call GraphObjClose("2DAxis1_XAxis1")
And:
When I open the “Curve and Axis Definition” window of the graph on the report page ,and set the “Format:” function to display “d.dd” It seems the script is overwriting the format that I set.
This is what I have now and would like to display only 2 decimal places in the X Axis. Can you help?
Thanks!
SJD
Solved!
Go to Solution.
Attachments:
X-Axis Decimal places.jpg 17 KBThanks Brad for you quick response.
It kind of worked... I think I might have something else going on. Not sure what though.
With the changes made in the script you suggested, the X-Axis has changed to two digits but now it displays " 1.dd "
Any thoughts where else I might have gone wrong?
Thanks again
SJD
Attachments:
2013-03-13_151027.JPG 12 KB -
Formatting Numeric Only with Variable Decimal Places
Acrobat Pro 9, Windows XP
I'm creating a form that has a number of text box form fields that are to be numeric only per the form requestor. However, for any given field of this type the number of decimal places that can be entered can vary from 0-3 and the requestor does NOT want any unnecessary decimals to appear in the final output (e.g., a "1.2" entry should not appear as "1.200"). The standard number formatting properties always show all the decimal places so I know it's not that route. No calculations will be performed with any of these entries -- the form requestor merely is entering data and then printing it out so that it's legible for the end-user.
I know that the following line of JavaScript in the Custom Keystroke property limits the entry to numeric only, but how should I tweak the syntax to allow a decimal entry:
event.rc = (!event.change || /^\d$/.test(event.change))
I probably also need a script to format for decimal places, but I don't know where to look in the JavaScript for Acrobat API Reference or in the MDN JavaScript Reference.
Thanks in advance for any assistance.Good question. To keep it simple (because there are about 300 form fields in this document), if they choose to add extra decimal zeros, then who am I to argue with their entry. So in your example for a given form field, if they enter "1.200" then I expect that they want "1.200" to display.
OK, but earlier you said:
"However, for any given field of this type the number of decimal places that can be entered can vary from 0-3 and the requestor does NOT want any unnecessary decimals to appear in the final output (e.g., a "1.2" entry should not appear as "1.200")."
This seems inconsistent. Can you clarify? The point is the code and where it's placed depends on this. It could be implemented either as a custom Validate or Format script, in addition to a Keystroke script. -
GUI download, how to retain format of decimal places
Hi everyone!
I have a program that downloads data to excel file using GUI Download. The values of the amount in the ALV display are 11.90, 11.90- which is correct because it has two decimal places. But the problem now occurs in the excel file. The values are now 11.9, 11.9-.
Do you know of any method that will retain the format of the values when it is already in the excel file.
The format of my decimal notation is 1,234,567.89.
Thanks in advance.Thank you!
But I need to have the format of the numbers in the excel the same as the format in the ALV <b>without changing the format of the cells in the excel file</b>. It has to be changed in the program.
Actually there are also amounts that are being displayed in excel file with 2 decimal places the same as the ALV display. But some of the amounts were changed when it comes to the excel file, and I don't know why this happens.
Thanks.
Message was edited by:
Betsie Camoro -
What's the preferred way to format a number (which will converted to a string for display) to 2 decimal places?
var someValue = 1234.567;
var a = "{%10.2f someValue}";
Maybe you are looking for
-
I want to know when I am eligible for an upgrade?
I want to know when I am eligible for an upgrade?
-
Sync Lotus Notes for Mac to iCal?
Hey, I'm a Mac User in a mostly PC-based office. Everyone here uses Lotus Notes for Email & Calendar. For a long time I've been able to get away with using Mac Mail and iCal but all email invitations I receive are usually off by a couple of hours due
-
When I power up a small folder appears against a grey screen. Insode the folder are alternating question mark and finder icon.
-
Prolong backlit time display in iPod Classic
Gentlefolk; The display on my iPod Classic defaults to current time and battery status. Perfect. But, to see the time, when I touch a control, the backlight comes on, then the song title displays, when all I really want to do is see the time. Is ther
-
OSX CS3 - Quits upon Launch - never worked
I bought the 30 day trial DVD for Web Premium CS3. I have an iBook - 700mhz. Running OSX - 10.4.11 currently. I installed the whole CS3 web premium suite of applications yesterday as soon as I received the DVD in the mail. I installed all the program