Rounding up one decimal?
I have a number that looks something like this:
0.552
I would like to round it up to a one decimal number like this:
0.6
How can I do this?
Thanks a lot!
num=0.552;
Math.round(num*10)/10;
Similar Messages
-
Rounding a quantity field to one decimal place. PLEASE URGENT
I have a quantity field with three decimal places. I have to print this field with only one decimal place. This is in a smartform.
suppose: qty = 45.678
I want it to be printed as 45.7
Thanks in advance.Hi Riki,
I think you can use Function Module ROUND to round off the value...
REPORT ZTEST_SHAIL4 .
data: out type p decimals 1,
inp type f.
inp = '45.678'.
CALL FUNCTION 'ROUND'
EXPORTING
DECIMALS =
input = inp
SIGN = ' '
IMPORTING
OUTPUT = out
EXCEPTIONS
INPUT_INVALID = 1
OVERFLOW = 2
TYPE_INVALID = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Now use the variable 'out' to display the rounded off value...
Regards,
SP. -
Quantity field to one decimal place. PLEASE URGENT
I have a quantity field with three decimal places. I have to print this field with only one decimal place. This is in a smartform.
suppose: qty = 45.678
I want it to be printed as 45.7
Thanks in advance.Create one more variable in Global definitions with only 1 decimal place.
Assign value of qty to this new variable.
SAP automatically takes care of the rounding.
And then print this new variable rather than qty.
You can write all these in a code block. -
Rounding to 1 decimal place.
Hello again.
I have a method called "findTheAverage" which takes in an array of integers as a parameter and then calculates and returns the average as a float.
What I want to do now though is create another method called "roundTheAverage" which takes in the float average variable from the previous method, rounds it to one decimal place, and then returns it as a float called roundedAverage.
Could anybody help me in achieving this?
Thanks.I'm fairly new to Java, hi.
Oh I know all about you.
I'm trying to write a method which takes in a float
called "number" and then returns this float to two
one decimal places called "roundedNumber".
This is not the way this works. You have to write your own code.
>
Could you type me the code that I'd need to do this
perhaps?
Nope.
It's a pretty simple problem I think, and it's
wasting an enormous amount of time figuring it out.
You are right on both counts. It is very simple and you are wasting alot of everyones time.
>
thanksAPI Application Programming Interface
Javadoc API
In context for this site means the documentation for the basic packages that make up the core Java API.
I provided a link earlier to the Javadocs for java.text.DecimalFormat
If you can't figure it out you need to HIRE A TUTOR. -
Hi Friends
i need to do rounded to two decimal value of required view attribute(messageStyleText).
How can i get the value-> round the value ->set this rounded value in same view attribute again.
This thing planing to do by extending the CO.
I extended the VO but its not working...
can anybody suggest how can we do this in controller..
Regards
--HarryHi Anil,
Thanks for your reply..
I tried the below code..but its not seting the value
code:
if(pageContext.getParameter("EBtn") != null)
OAViewObject vo =
(OAViewObject)am.findViewObject("UpdateVO");
String ss1 = vo.getCurrentRow().getAttribute("ECost").toString();
pageContext.writeDiagnostics(this,"@123ECost Value is: " +ss1,1);
double d = Double.valueOf(ss1).doubleValue();
DecimalFormat df = new DecimalFormat("#0.00");
String ss2 = df.format(d).toString();
pageContext.writeDiagnostics(this,"@12345Estimated Value with 2 decimals: " +ss2,1);
vo.getCurrentRow().setAttribute("ECost",ss2);//its not seting the value
//I tried the below code also..but no use
/*OAMessageStyledTextBean oastb = (OAMessageStyledTextBean)webBean.findChildRecursive("WOEstimatedCost");
oastb.setValue(pageContext,ss2);*/
Can any one please help me out
Regards
--Harry -
When using Math.round, I know to round to 2 decimal places it would be Math.round(variable * 100.0)/100.0. I have this in one program and it works. (answer = Math.round(answer*100.0)/100.0;) I have it in another program and it doesn't (double answer = Math.round(balances [looper]*100.0)/100.0;// balances is declared as double balances [] = new double [numberOfCustomers];) What am I doing differently that I should be looking for.
Hi,
Please try using java.text.DecimalFormat class. This class is a subclass of java.text.NumberFormat. You can read about this class from JDK documetation.
HTH
VJ -
Rounding to 2 decimal places in Derived column transform editor
I want to replace the contents of a value column with itself but rounded to 2 decimal places.
The current column is a double and I have tried to perform this using the following expression but it fails to work.
Code Snippet
Round(cc_vl,2)
How should I achieve this?I’ll take a guess here but you started with this –
123.45678
Got this –
123.45000
Wanted this –
123.45
So the 123.45000 is absolutely correct, the value has been rounded to 2 digits. A double however has a scale greater than 2, and you only wanted two digits after the point because you were concerned about how the value looked rather than the actual value. This is certainly not a bug. It is how you format the data for display.
Your solution is the way to do this, either on the Derived Column or Data Conversion Transformation. You got it in the end, the replace versus new, because you cannot change the type of a column. You may convert the value, but the storage type of the column means it will implicitly revert to the base column type when you put it back, albeit with a value that has been rounded.
Does that explain it? -
Amount has moved one decimal place in the report
Hi,
I am looking in to a report at present, Transaction amount has moved one decimal place, while the local amount stays the same. Any one could tell me the possible reason for this?
Thanks in advance
RNHi,
Check this link,
http://sap.ittoolbox.com/groups/technical-functional/sap-bw/key-figure-in-cube-is-multiplied-by-100-when-displayed-in-bex-report-743076
same issue find in this.
Hope it will help you.
Thanks,
Hema -
Regular Expression to Check number with at least one decimal point
Hi,
I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
Ex.
10.1
1.1
1
12
This is what I have so far. Any help would be appreciated. Thanks.
if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') tHi,
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
SammyStyles wrote:
Hi,
I would like to use the REGEX_LIKE to check a number with up to two digits and at least one decimal point:
Ex.
10.1
1.1
1
12
This is what I have so far. Any help would be appreciated. Thanks.
if regexp_like(v_expr, '^(\d{0,2})+(\.[0-9]{1})?$') t
Do you really mean "up to two digits", that is, 3 or more digits is unacceptable? What if there are 0 digits? (0 is less than 2.)
Do you really mean "at least one decimal point", that is, 2, 3, 4 or more decimal points are okay? Include some examples when you post the sample data and results.
It might be more efficient without regular expressions. For example
WHERE TRANSLATE ( str -- nothing except digits and dots
, 'A.0123456789'
, 'A'
) IS NULL
AND str LIKE '%.%' -- at least 1 dot
AND LENGTH ( REPLACE ( str -- up to 2 digits
) <= 2 -
Hi,
I am trying to round the decimal place of number 0.105 as .11.
But it only rond up to 0.1 not 0.11.
I don't understand why it doesn't round to 0.11.
Can any one explain to me ?
My code :
import java.util.*;
import java.text.*;
import java.math.*;
public class TestFile {
public double number = .105;
public static void main(String[] args) {
TestFile test = new TestFile();
DecimalFormat aFormat = new DecimalFormat("#.##");
int decimalPlace = 2;
double num = .105;
BigDecimal bd = new BigDecimal(num);
bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP);
//DecimalFormat aFormat=new DecimalFormat("###.00");
String formattedString = aFormat.format(test.number);//format the String entered
System.out.println("formatted string: " + formattedString);
System.out.println("big decimal " +bd.doubleValue());
double formattedDouble = Double.parseDouble(formattedString);//convert to a double
System.out.println("back to a double: " + formattedDouble);
What should I do to round 0.11 ?
Thanks,
njan.BigDecimal bd = new BigDecimal(num);Change this line to
BigDecimal bd = new BigDecimal(Double.toString(num));Read the notes in the API for BigDecimal constructor that accepts double.
http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(double)
The results of this constructor can be somewhat unpredictable... -
like, right now i have this huge equation;
double heatIndex8 = (-42.379) + (2.04901523 * birmingTemp[7]) + (10.14333127 * birmingHum[7]) - (0.22475541 * (birmingTemp[7] * birmingHum[7])) -
(6.83783 * Math.pow(10, -3) * Math.pow(birmingTemp[7], 2)) - (5.481717 * Math.pow(10, -2) * Math.pow(birmingHum[7], 2)) +
(1.22874 * Math.pow(10, -3) * Math.pow(birmingTemp[7], 2) * birmingHum[7]) + (8.5282 * Math.pow(10, -4) * birmingTemp[7] * Math.pow(birmingHum[7], 2))
- (1.99 * Math.pow(10, -6) * Math.pow(birmingTemp[7], 2) * Math.pow(birmingHum[7], 2))and it prints out an insane amount of decimal places...
how can I tell the code to round(heatIndex8) to the tens place?paulcw wrote:
Use a java.text.DecimalFormat, or one of the printf methods that are now all over the place. (Well, String and java.io.PrintWriter and PrintStream, in particular).
By the way the size of the equation doesn't have a lot to do with it.
Edited by: paulcw on Feb 2, 2008 1:23 PMI know it doesn't, but I just really hate it.
decimal format you say? I'll go check that. -
Round to two decimal places...and keeping trailing 0
Ok, I have done a search on rounding. So I made this function:
private double round(double number){
double d = Math.pow(10, 2);
return Math.round(number * d) / d;
}However, if I use a number like 3.59999, it returns 3.6. For what I am using it for, I need it to return 3.60. Any ideas? Thanks.You normally only format for display! You seem to be wanting the default format to show 2 decimal places. This makes no sense. Internally a number(double or float) doesn't know about decimal places so how can the default format know you want 2 decimal places?
For the most part you only need to worry about decimal places when you print a number using the DecimalFormat class.
There are times when you might want to round values to 2 decimal places before doing more calculation. I have only met this when adding monetary values when it is important that a column total equals the sum of a displayed column values. In this case one uses something like the technique you originally proposed to round values before summing them. You then use DecimalFormat to display the values. -
TIMESTAMPDIFF rounding to 2 decimal places instead of 0
Hi,
Requirement is to find difference between two timestamp column,
as known one we cannot perform arithmetic operation in non number type in rpd.
Hence tried using TIMESTAMPDIFF function as below,
TimeStampDiff(SQL_TSI_MINUTE, MONITOR_TIMESTAMP, ATT_TIMESTAMP" )
OBIEE server converting this function to below SQL ,
ROUND( ( CAST(ATT_TIMESTAMP as DATE) - CAST(MONITOR_TIMESTAMP as DATE) ) * 1440 )
this returns value as ex: 12 as rounded value without any decimal places.
but we want to have two decimal places, how to fix this or any work around ?
Thanks,
Satheeshinstead of * 1440
do with
* 1440.00
btw: why you need to cast to date? why cant be timestamp?
Discard it -
hello guys,
I have a table. One column of the table displays the scores.
ex: 2.2222222233333
2.32232323
I want to round all the numbers in that column to 2 decimal.
Result needed: 2.22
2.32
Can you please help me how can i get handle to the column and round the numbers to 2 decimal places.Boris,
1) You mentioned "i tried finding out the VO", I am not sure how you checked it.
Enable diagnostics then you will get a link in the Bottom left corner called "About this page",
click on that , and expand it, you can see the page structure there, there you can find the attached VO with your table region.
Or
begin
jdr_utils.printDocument('<your page path like /oracle/apps/per/....PG>');
end;
Which will give the PG.xml you can load the page in Jdeveloper(with the same package)
and you can have a look at the page structure in the page, which will give details about what VO is attached to your table region.
2) Yes you are right, you cannot round the null value
3) What page you are trying to get round the value, is it the FinalAppraisalPG?
Give me the full navigation,
Thanks.
With Regards,
Kali.
OSSI. -
Rounding to 2 decimal places WITHOUT using any formatting class
Hello
I'm trying to round a number (double) to 2 decimal places without using any of the formatting class like (DecimalFormat or Math.Round and BigDecimal). Is it possible to do it by just using typecast?OP:
BigDecimal is not a formatting class. Math.round isn't a class at all.
Typecasting doesn't really do that sort of thing at all (unless you count dropping fractional components when casting to an integer type).
double holds values in binary format, so it's basically impossible to round to decimal values meaningfully.
Chuck:
I thought that BigDecimal supported arbitrary decimal precision, so one doesn't have to do that sort of thing....?
Maybe you are looking for
-
I prevsiouly owned an Ipad. Before selling it, I backup it on my Macbook. When the new Mavericks has been released, i upgraded my Mac. Now that I have iBooks on my Mac, I want to restore my iBook collection from my previous Ipad to my Mac. On my Mac,
-
Burning 16:9 video and DVD Playback
Hi, I have been trying to burn a 16:9 video (exported from FCP 5 at 853x480) in iDVD 5.0.1 and play it back on my Toshiba SD4000 DVD player. However, everything I try (even setting the player to 16:9 video) results in the video getting stretched to a
-
Declaration of constant errors
I'm having a bit of a problem here. I just changed my variables into constants, and I'm getting errors on it. I can't pin point the problem can someone help me out. public class MazeException extends Exception final String message; final Thro
-
Library won't play after upgrade to 6.0.4
I have just recently upgraded to 6.0.4 and now i am unable to play tunes from my library. I can play samples etc from the music store, but my Library is dead. Just to confirm, if i remove and reinstall itunes from my pc, my library remains in my pc f
-
PPro CS5 not talking to NVidia Quadro 4000...
Apologies in advance if this has been covered a million times on here (and feel free to point me to a thread), but...I have a new Mac setup, Adobe PPro CS5, and the NVidia Quadro 4000 card with MPE/Cuda. And PPro is not using the GPU. I do have the l