Rounding up decimal places
Hi,can anyone please tell me how to round up a double type value to 6 decimal places.
Thank You!
You should be able to adapt this solution I posted last week:
http://forum.java.sun.com/thread.jsp?forum=31&thread=412237
Changing the int's to double's will probably work fine.
Cheers,
Radish21
Similar Messages
-
Rounding to decimal places in Captivate 6
I need some assistance with rounding to 2 decimal places in Captivate 6. Can this be done without scripting?
VinceRod or anyone
Would you be able to direct me to where I would be able to find the Javascript for rounding a variable to 2 numbers in Captivate 6?
Vince -
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... -
Displaying results with a decimal place of two. Forcing decimal place.
Hi there,
Im writing a simple calculation device.
You input one digit and press one of two buttons to multiply it by a certain number and then the result is displayed. The result is displyed hiding the result of the button you didn't press and visa versa.
I am having a problem displaying the result with a constant two decimal place.
I am using strings and thus don't know how to do this.
Here is my code:
import flash.events.MouseEvent;
//restrict the input textfield to only numbers
txtinput.restrict = "0-9";
//restrict the input textfield to only two characters
txtinput.maxChars = 6;
// event listeners
btnW.addEventListener(MouseEvent.CLICK, WHandler);
btnC.addEventListener(MouseEvent.CLICK, CHandler);
btnW.addEventListener(MouseEvent.CLICK, hideC);
btnC.addEventListener(MouseEvent.CLICK, hideW);
//functions
function WHandler (e:MouseEvent):void
//white calculation
var answerW:Number = Number(txtinput.text) * Number(0.90);
txtWResult.text = answerW.toString();
function CHandler (e:MouseEvent):void
//colour calculation
var answerC:Number = Number(txtinput.text) * Number(0.99);
txtCResult.text = answerC.toString();
function hideC (e:MouseEvent):void
//Hide colour result
txtCResult.visible = false;
txtWResult.visible = true;
function hideW (e:MouseEvent):void
//Hide white result
txtWResult.visible = false;
txtCResult.visible = true;
After having a look online I have found these two resources:
http://helpx.adobe.com/flash/kb/rounding-specific-decimal-places-flash.html
and
http://stackoverflow.com/questions/11469321/decimals-to-one-decimal-place-in-as3
But I am confused when combining these techniques with strings.
Any help would be greatly appreciated,
Thanks in advance
Mr BUse the toFixed() method of the Number class instead of the toString() method. The result of it is a String with the number of decimal places you specify.
var answerW:Number = Number(txtinput.text) * Number(0.90);
txtWResult.text = answerW.toFixed(2);
var answerC:Number = Number(txtinput.text) * Number(0.99);
txtCResult.text = answerC.toFixed(2); -
Rounding up to a particular decimal place
Hi,
I'm bringing a field into my report that uses up to eight decimal places. I'm tasked with rounding things up to the fifth decimal. Rather than rounding when the number is five or higher, it should always round up if it is above one.
So for example:
2.03827893 rounds up to 2.03828000
11.40032180 rounds up to 11.40033000
Any ideas on the best approach for achieving this within a Crystal formula?
Any help would be greatly appreciated.
Thank you.Hi Bob,
Right click on the field and select "Format Field"
In "Number" tab, select "Custom Style" then click on "Customize"
In the Roundig box you can select the Rounding type.
--Praveen G -
Rounding To Nearest Decimal Place
Hey Flash Family,
I am getting the correct output i want but is also giving me
like 8 numbers after the decimal place...all i want is the numbers
rounded to the nearest cent meaning only 2 numbers to the right of
the decimal point....what do i need to add to the current code to
correct this issue.
Thanks N Advanceattach that code to the first frame of your main timeline.
then anytime you need to change the format of a number like
_root.how.ROIM.val_tcost use:
_root.return2DecPlaces(_root.how.ROIM.val_tcost); -
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. -
Rounding to two decimal places in BPC/NW
Hello,
I am dealing with the task to round values to two decimal places. I have found some discussions in BPC-MS where the statement ROUND should work in logic. Unfortunately I am not able to make it work in the NW version.
Isn't there also a parameter in the appset or application administration which would cut the numbers only to two decimal places (this task would be also a possible solution for us).
Thanks for any help
JanHello Pravin,
the second import worked fine. I realized that the class has changed to ZCL_BPC_SL_ROUND.
I debugged the class and noticed that the parameter it_cv is not filled at all. Therefore the program ends before starting the rounding procedure. Here is the part of the code:
Take CV into account
clear l_success.
loop at it_cv into ls_cv.
clear l_val_string.
loop at ls_cv-member into l_member.
if sy-tabix eq 1.
l_val_string = l_member.
else.
concatenate l_val_string l_member into l_val_string separated by ','.
endif.
endloop.
if l_val_string ne space.
l_success = add_dim_restriction( i_param = l_val_string i_dimension = ls_cv-dimension i_clear = abap_true ).
if l_success eq abap_false.
concatenate 'Failed to successfully add Dimension' ls_cv-dimension into l_log_msg
separated by space.
cl_ujk_logger=>log( l_log_msg ).
cl_ujk_logger=>log( 'Exiting Round Method' ).
cl_ujk_logger=>empty_line( ).
raise exception type cx_uj_custom_logic
exporting messages = et_message.
exit.
endif.
endif.
endloop.
if l_success eq abap_false. exit. endif. - here the program exits and therefore doesn't do any rounding.
If I comment this part the system rounds correctly but runs on all records in the cube which degrades performance a lot.
Could you please advice further if it is possible to restrict the data region only to the submitted data?
Best regards
Jan -
Rounding Rule upto 3 Decimal Places in Tax Condition(SABRIX)
Hi,
We are Using SABRIX for Tax determination and need to round up Condition Type XR1- XR6 to round upto 3 Decimal Places.
Do we need to To Change ALT Calc Type- 301306or Alt Cond Base Value -- 16 or have to change Currency decimal Places in transaction OY04/OY03.
Kindly Suggest.
Thanks
AmitHi,
Tax % for customer is decided in SABRIX, Where does TaX calculated?? In SABRIX or in SAP.
Thanks
Amit
Edited by: AMIT GUPTA on Mar 31, 2010 10:54 AM -
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? -
Rounding Doubles to Two Decimal Places
Hi All,
I've searched the archive and found a few different posts regarding restricting the number of decimal places in doubles. However they all suggest different methods, BigDecimal, NumberFormat etc.
Which is the simplest method of rounding a number say 10.023445656 to 10.02?
I tried using the java.text.NumberFormat but this turns the double into a string and I need the end result to be a double.
ThanksHi All,
I've searched the archive and found a few different
posts regarding restricting the number of decimal
places in doubles. However they all suggest different
methods, BigDecimal, NumberFormat etc.
Which is the simplest method of rounding a number say
10.023445656 to 10.02?
I tried using the java.text.NumberFormat but this
turns the double into a string and I need the end
result to be a double.
ThanksI ahve a small code that can do the work for u:
import java.text.*;
double format(double val, int dec){
double multiple=Math.pow(10,dec);
val=Math.round(val*multiple)/multiple;
DecimalFormat df=new DecimalFormat("0.00");
String format=df.format(val);
double dval=Double.parseDouble(format);
return dval;
}//end of functionHope that helps! -
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. -
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. -
BED & AED Round up or down without decimal places
Dear Gurus,
My client wants BED & AED Round up to nearest value without Decimal places.
I am using taxinn procedure and JMOP for BED and JAOP for AED As a condition.
I tried to tick round up in condition , but it is not workig.
Please help.Hi,
In TAXINN T code : OBQ3 against ur condition in alternative calculation type (Calty ) column put 17.
At the same time OB90 against ur company code put 100.
Then ur problm will be resolved.
Biswajit -
Hi Gurus,
I want to reduce the number of decimal place by rounding off 2 decimal place.
I am using 'HR_NZ_ROUNDING_DECIMALS' function module but its not working,
kindly do the needful.
Regards,
MaithiliHi,
Use Type cast method instead of finding FM.
DATA : i type p decimals 4 VALUE '57846.5379'.
DATA : j type p decimals 2.
j = i.
Write : / i.
Write : / j.
Regards,
Velmurugan B
Maybe you are looking for
-
How to update TEXT in Sales order header
Hello , I have requirement in which I am creating SO via IDOC calling BAPI_SALESORDER_CREATEFROMDAT2. Question: Can any one help me in finding a solution to update the TEXT in sales order header which is confogured IN TEXT CONTROL in SD. I have tried
-
Sort a string :: Please help.
Hello Everyone, I am having this very simple problem of sorting a String. please help. static String sortString(String str){ List list = Arrays.asList(str); Collections.sort(list); for(int i=0, n
-
Hello, I recently purchased a Mid-2012 MacBook Pro 13". It came with OSX Mountain Lion. I had a friend set it up, and they created their account with administrator permissions, and I had my own administrator account on it. Their account was created f
-
Want to sync without loosing a ton of data (again)
I'll apologize in advance for such a long post, but I'm not sure what else to do. iTunes, during my version upgrade, lost months of my personal data. Question: I'm wondering if there is a way to back up my data on my phone and be really sure it (my d
-
Hi All, I am getting the following messages when I do CIFing PPM. "No entry found in transportation indicator table for objectu201D /SAPAPO/PPM_TRANSFER104 and u201CActivity P found neither in database nor in tables". /SAPAPO/PPM_TRANSFER107 We want