How to correct a double value to two decimal places
hi,
How to correct a double value to two decimal places
eg.
double tt=100.100032
i want to correct to 2 decimal places
ie tt=100.10
regards,
jagan
Check my other reply on the other thread. Please don't cross-post.
Similar Messages
-
How can I limit a double value to two decimal place?
How can I limit a double value to two decimal place?
Java keeps on adding zero's to a simple double subtraction:
1497 - 179.64 = 1317.3600000000001The answer must have been simply: 1317.36If the trouble is with output ...
If the trouble is with value accuracy ...The trouble is with OPs understanding of and/or expectations of IEEE 754 floating point numbers. o_O
[And it's probably a view (output) issue.]
how can i actually use numberformat to cut those
unwanted decimal places?Read the API - Puce already provided the link. -
Any function module to round of a value to two decimal places?
Hi gurus,
Any function module to round of a value to two decimal places?Hi,
you can use FM 'ROUND'.
Thanks. -
Help!printing float values with two decimal places
hi there java pips! im a newbie to this technology so forgive me for this really stupid question....i would like to perform mathematical operations on two float values....the problem is i want to print them in a standard format and that is i want them to be displayed with two decimal places (e.g 190.00, 12,72, 1,000.01) how can i do this?
Try java.text.DecimalFormat
NumberFormat nf = new DecimalFormat("0.00");
System.out.println(nf.format(x)); -
How to restrict decimal values upto two decimal places?
Hi all,
I want to restrict decimal figures upto two places. How to do that? Help will be appreciated.
atanu
[email protected]You can use NumberFormat class.
There are lot of threads available in this forum. Just search for the keyword 'NumberFormat'. -
Double value truncated to two decimal places without rounding the value.
I want to truncate double value to two decimal places without doing the rounding of the value.
Is there any method which can directly do the truncation.There's many ways to achieve this such as using
BigDecimal's setScale method or type-casting. This is
the way I like to do it:double d = -5.239;
d = d > 0 ? Math.floor(d * 100) / 100.0 : Math.ceil(d
* 100) / 100.0;
Your division by 100 may cause an rounding error, because there are numbers which no finite binary representation. That's splitting hairs! I know ;-) -
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 off to two decimal places
Hello,
For simplicity, is there a method which will round off
a double variable to two decimal places.
Excample: if I have a result which equals 2.1999998
and I want to display this as 2.20 in a TexTField.
Any help would be much appreciated.
ThanksIf you are trying to do dollars and cents, I further recommend you use:NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
String currencyOut = currencyFormatter.format(yourNumber);to format your numbers as they will give the correct precision for international currencies simply by setting the locale, and they will also automatically handle the currency symbols ($, DM FR, etc.)
Doug -
Convert amount with four decimal places to amount with two decimal places
Hi,
for specific reasons we have set the prices to four decimal places. However, in an invoice the staff needs to see all prices with two decimal places. Therefore I have created new user-defined fields which should show the rounded values However, I have not yet found the right formatted search that outputs the value with two decimal places including currency symbol.
The statement
SELECT $[$38.20.NUMBER]
outputs the value with two decimal places which is fine, but it does not contain the currency.
The statement
SELECT $[$38.20.0]
outputs both value and currency, but the value still has four decimal places as the original price.
And the statement
SELECT CAST($[$38.20.NUMBER] AS VARCHAR(20)) + $[$38.20.CURRENCY]
outputs a value with even six decimal places.
Did anyone already have the same problem???
Or does anyone have any idea???
Thanks and regards
CorinnaHi again,
the value should be displayed in a user-defined field of the screen.
The result of the query
SELECT $[$38.20.NUMBER]
has already two decimal places, so that I do not need a round here. But the currency is missing.
When I add the round function to the query
SELECT $[$38.20.0]
it does unfortunatly result in an error.
Any ideas????
Thanks so much in advance! -
Limiting AS distance to two decimal places
I am just about there getting the Google Maps API talking to my SQL database. For my search results I have the SQL:
SELECT *, ( 3959 * acos( cos( radians(" .$POST["latitude"] .") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" .$POST["longitude"] .") ) + sin( radians(" .$_POST["latitude"] .") ) * sin( radians( lat ) ) ) ) AS distance FROM VenuesGeocodes1 HAVING distance < 100 ORDER BY distance LIMIT 0 , 30;
Which works great, but displays the distance with 15 decimal places which is complete overkill.
How can I limit that to just two decimal places? I thought I just needed to change distance to distance (10,2), but it didn't like it.
If anyone can let me know what it should be that would be much appreciated.
Thanks.Thanks Rob - I also got it to work using ROUND in the query:
SELECT *, ROUND( 3959 * acos.... -
Formatting Strings to two decimal places
When formatting double amounts to two decimal places, I looked up the procedure online and I have this so far:
public void calculatePayments()
double monthlyInterestRate = (Double.parseDouble(interestBox.getText())/12)/100;
double amountOfLoan = Double.parseDouble(balanceBox.getText());
double numberOfPayments = Double.parseDouble(yearsBox.getText()) * 12;
DecimalFormat Currency = new DecimalFormat("0.00");
double paymentAmount = (amountOfLoan * monthlyInterestRate) / (1 - Math.pow(1/(1 + monthlyInterestRate),numberOfPayments));
double formattedAmount = Currency.format(paymentAmount);
String s = Double.toString(paymentAmount);
tableBox.append(s);
tableBox.setText("Payment" + "\n" + "Number" + "\n");
for(int i = 0; i <= numberOfPayments; i++)
tableBox.append("" + i + "\n");
However, I get the following:
ProgramInterface.java:134: incompatible types
found : java.lang.String
required: double
double formattedAmount = (Currency.format(paymentAmount));
I'm trying to append the number to a text box (I'm making a loan calculator for my 155 class) Thanks for the helpString s = Currency.format(paymentAmount);Next time please paste your code between code tags exactly like this:
[code]
your code
[/code]
You can do that by simply pasting your code in the message area, highlight it and then click on the code button above.
You may read the [url http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips for more information.
Regards -
From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?
Hi,
Use NVL or COALESCE:
NVL (col_a, col_b)
Returns col_a if col_a is not NULL; otherwise, it returns col_b.
Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How do I correct % complete to show whole numbers, not two decimal places
I just installed version P6 6.2 on my laptop and restored a schedule. The percent complete is showing two decimal places for activities less than 100%. What I would like is to have whole percentages, e.i. 84%, not 83.76%. How do I correct this? I thought it would be under the user preferences, but it's not there.
Edited by: 795589 on Sep 20, 2010 5:46 AM
Edited by: 795589 on Sep 20, 2010 5:47 AM*795589,*
What particular percent complete are you having trouble with?
*(Found in the P6 knowledgebase) This issue is an existing Enhancement Request. It will be considered for a future release*
Other than that, maybe try creating a global change to manually calculate your percents.
hope this helps,
+*** Can the number of decimal places for Percent Complete be changed? [ID 895884.1] Modified 30-OCT-2009+ -
Hi All,
Am using OPENROWSET to load the file data into table, here the problem is i need to map same input value to two different columns of table, As format file doesn't allow the duplicate numbers am unable to insert same value to two columns, please help me to
find a solution for this.
i can use only OPENROWSET because i need to insert some default values also which come based on file. only the problem is how to map same input value to two different columns of table. please give me the suggestions.
Thanks,
SudhakarFrom what you say:
INSERT tbl(col1, col2)
SELECT col1, col1
FROM OPENROWSET(....)
But I guess it is more difficult. You need to give more details. What sort of data source do you have? What does your query look like? The target table?
Erland Sommarskog, SQL Server MVP, [email protected]
Hi Erland,
Thanks for your response
my source file is text file with | symbol separate for ex:
1002|eTab |V101|eTablet|V100|Logic|LT-7|Laptops|SCM
Database table have columns like
column1,column2,column3...etc, now i need to insert same value from input file into two columns for ex:
the eTab value from text file has to be insert into column2 and column3 of
table
we cannot change format file like below one
for the above situation how can we insert eTab into column2 and column3
Thanks,
Sudhakar. -
How to take float precision to two decimal places?
Hi, everybody:
I'm a straight noob...first week in Java programming. Before you bash me for not checking FAQs and such, believe me, I have.
I have tried BigDecimal movePointLeft, but I don't know how to construct it using proper syntax. I also tried currency and toString but I keep messing up my syntax somehow. Four hours into this and nothing is working.
Here is the problem: I have a float. I want to format its output to two decimal places, trying to achieve in Java what C would produce as:
printf("The amount you owe is $%.2f", fltAnyName);
Any help would be appreciated.
Thanks,
RobSorry, guys. I have tried both recommendations and I can't get either to work. I'm getting a compile error pointing to the delineating period between the "out" and "printf" when I try the C-like code. I have 1.5, too. I know your advice is sound so I must be doing something wrong. Can you insert the code DecimalFormat code that will correct this problem where it needs to go? The packages below have been included becasue of all the different solutions I have attempted.
import java.io.*;
import java.math.*;
import java.text.*;
import java.lang.*;
public class CoinCalculator2
public static void main(String[] args) throws IOException
String strQuartes, strDimes, strNickels, strPennies;
int intQuartes, intDimes, intNickels, intPennies;
float fltValue;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
System.out.println("THE COIN CALCULATOR");
System.out.println();
System.out.print("Enter the number of quarters you have: ");
strQuartes = dataIn.readLine();
intQuartes = Integer.parseInt(strQuartes) * 25;
System.out.print("Enter the number of dimes you have: ");
strDimes = dataIn.readLine();
intDimes = Integer.parseInt(strDimes) * 10;
System.out.print("Enter the number of nickles you have: ");
strNickels = dataIn.readLine();
intNickels = Integer.parseInt(strNickels) * 5;
System.out.print("Enter the number of pennies you have: ");
strPennies = dataIn.readLine();
intPennies = Integer.parseInt(strPennies);
fltValue = (intQuartes + intDimes + intNickels + intPennies) / 100;
System.out.println();
System.out.println("The value of your coins is $" + fltValue);
System.out.println();
}
Maybe you are looking for
-
Hi guys and gals. Im looking for a program or a way to make a dvd with chapters. I have 2 xvid files that equal 1.4gb's. I'm doing it in toast 8 but it says theres not enough room to do this, and i cant figure out why. Is there another way i can conv
-
HI Experts, My scenario was Idoc to File. *Issue: I had mapped Source idoc with A,B,C,D fields. I want only A,B,C at final structure.* I cannot ignore D field in message mapping as i am using that field for file name Substitution in receiver communiv
-
MySQL database relation question
I'm setting up a site where registered users can catalog their Japanese Vinyl toys (i.e. vinyl kaiju). I have 2 tables: collection members members has an ID that is specific to each member (naturally). within collection I have kaijuID and userID. Wha
-
When I open FireFox Bing is the default search engine at the top right hand side of my bar. When I go into the control panel and the programs, I can't find Bing Bar to uninstall it. I'm using Windows 7. It seems to me that Windows is using techniques
-
Hello all, I need MM Certification manuals. Can any one please provide?? Regards, Aisha Ishrat ICI Pakistan Ltd.