Decimal places in double value
I am sending a number to my program - 99999999.99 and parsing it as double.
double d = Double.parseDouble("99999999.99");
When I print this out, it prints - 9.999999999E7
The problem is, my database won't accept it unless I provide this value exactly as '99999999.99'.
I truncated the decimals using DecimalFormat, but the database needs to receive the value as a number only, not as a String that is returned by format function.
How do I make my program pass the same value from the String, but as a number?
I am trying to pass it to a stored procedure, so setting it as -
cstmt.setDouble(1, Double.parseDouble("99999999.99"))
My problem is that the database field which corresponds to this is of type numeric(8,2).
When the number is parsed as double and is sent to the database it looks like this - 99999999.989999995, so the database rejects it.
Why is the number '99999999.99' being changed to '99999999.989999995' on converting it to double? How can I make it a double number, yet restrict the number of digits after decimal to 2?
Similar Messages
-
How to keep 2 decimal places for double value
Hi,
I need rounding function, which should round a double number till 2 digits, if there is no decimal part it should append 2 zero's in decimal places.
eg. 100 --- > 100.00
200.234 --> 200.23.
I tried with Number class. but it is returning string, from that string if I try to convert to double value, it is rounding off one digit.
Can any one help on this problem.
Thanks,
Suman.chI am using xmlBeans using that I need to write this
rounded value into a xml file, for that I need only
double value with 2 decimal places.You can probably write the value as a String instead of a double somehow, so you can use the DecimalFormat class.
You could try their mailing-lists for users/developers:
http://xmlbeans.apache.org/community/index.html -
Select amount field of a table with decimal place of 3rd value grater than 0.
Select all the reord in a table with amount decimal place of 3rd value grater than 0.
Can you show the sample data + desired result?
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Hi,
How do you limit the number of decimal places which are displayed by a double??
Cheers
Davidhttp://java.sun.com/docs/books/tutorial/i18n/format/index.html
-
How to change the decimal places in the value axis of a chart in WAD?
Hello,
The key figure in my chart has 2 decimal places and I want the value axis to show the same. How to do that?
Thanks in advance, NathalieHi,
change the Format property of the ValueAxis-Line to 0.00
Then the axis displays its values including two digits after the decimal.
Regards, Kai -
Printing two decimal places from BigDecimal values
I am using BigDecimal to represent money values. My output needs to line up so that (with a non-proportional font) the decimal point and the two decimal places are in the same columns for each line. But when the dollar value has zero cents, or has a number of cents that is divisible by ten, it drops the trailing zeroes, and drops the decimal point if the decimal places are both zeroes. For example, I want to see "25.00" instead of "25" and "25.50" instead of "25.5". It doesn't seem to make any difference if I set the scale to 2. (I have resorted to getting the toString() of the BigDecimal and hacking the string before I display it, but surely there must be an easier way?)
BigDecimal aaa = new BigDecimal("25");
BigDecimal bbb = new BigDecimal("25.0");
BigDecimal ccc = new BigDecimal("25.00");
BigDecimal ddd = new BigDecimal("25.5");
BigDecimal eee = new BigDecimal("25.50");
BigDecimal fff = new BigDecimal("25.75");
aaa.setScale(2);
bbb.setScale(2);
ccc.setScale(2);
ddd.setScale(2);
eee.setScale(2);
fff.setScale(2);
System.out.println("SCALE SET TO 2: ");
System.out.println("aaa = " + aaa);
System.out.println("bbb = " + bbb);
System.out.println("ccc = " + ccc);
System.out.println("ddd = " + ddd);
System.out.println("eee = " + eee);
System.out.println("fff = " + fff);produces this output:
SCALE SET TO 2:
aaa = 25
bbb = 25.0
ccc = 25.00
ddd = 25.5
eee = 25.50
fff = 25.75Thanks,
MartinThankyou Dr. Clap. This solved my problem - I added an LHS to the setScale statements:
aaa = aaa.setScale(2);
bbb = bbb.setScale(2);
ccc = ccc.setScale(2);
ddd = ddd.setScale(2);
eee = eee.setScale(2);
System.out.println("SCALE SET TO 2: ");
System.out.println("aaa = " + aaa);
System.out.println("bbb = " + bbb);
System.out.println("ccc = " + ccc);
System.out.println("ddd = " + ddd);
System.out.println("eee = " + eee);produced:
SCALE SET TO 2:
aaa = 25.00
bbb = 25.00
ccc = 25.00
ddd = 25.50
eee = 25.50 -
Lost Decimal Places when extracting value from ODS into Cube
Hi,
In short, we wish to transfer data from an ODS to a custom cube. One of the Key Figures is becoming an integer in the process.
Both the ODS and Cube use the same InfoObject which is defined as a Number with a Data Type of FLTP.
If I set a break-point in the update rules, I can see that it is reading the value into the communication structure correctly. Yet, when I browse the data in the Cube, it seems to have lost the decimal places in the update.
More details:
We have a custom ODS and cube which needs to store a Unit Price to four decimal places. In creating the InfoObject for Unit Price, we could not use a Data Type of Currency (Type = Amount) as this is limited to 2 decimal places.
Instead, I used a Data Type of FLTP (Floating Point) and a type of Number. All decimal places are loading correctly into the ODS, but are being lost when transferred to Cube.
Many thanks
AdrianHi Simon and Emmanuel,
Thanks for the suggestions.
Unfortunately the Query is returning the same integers as LISTCUBE.
Also, my key figure has the same definition in both the ODS and cube (uses the same InfoObject), and there is no transformation - just transfer.
I'd prefer not to create another currency. It could get a bit messy if I'm having to include the figure in calculation with other figures that use the real currency.
I had thought of making the key figure a standard type of Currency and multiplying the value by 100 before storing them in the cube - then I would simply divide the figures by 100 in the query. But again, not ideal.
I have logged a OSS note with SAP to see if there is any known issue with transferring a floating point number between the ODS and Cube.
Thanks
Adrian -
Decimal places in condition value
Dear Experts
How can I configure the number of digits to appear after decimal point?
For example: 45.0 to 45.00
Regards
SDCHi,
In SPRO, go to general settings - currency-- change decima places for currency ...
I think the above path will help u to configure..
regards
sankar -
Hi QM Gurus,
I would like to know as how this field NKSTAT is populated in table TQSS1 - Table.
which customizing step is this maintained?
I checked in QM settings at Plant level - customizing step too..
Thanks in advance !!Hi,
I think issue is not of config. pl check your table seting.
se16 -
>TQSS1----->add desired details like plant etc and execute -> settings (Header) - format list---> choose fields -
>click on your field NKSTAT and other desired feilds and copy . definately your field is gate populate in your table.
Cheers, -
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,
jaganCheck my other reply on the other thread. Please don't cross-post.
-
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! -
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 -
Setting double value precision
Is there any way to set the precision on a double.
Example:
double = 25.00016000207654
precision = 4 decimal places (or some value 'x')
So I am looking for 25.0002 (this value will then be converted to a string and then displayed).Here is a simple little program that will allow you to round and format the way you wanted:
import java.text.*;
public class testFormat {
public static void main(String[] args) {
double x=25.00016000207654;
x=Round(x,4);
DecimalFormat NF=new DecimalFormat("0.####");
String formatted=NF.format(x);
System.out.println(formatted);
public static double Round(double x, int dec) {
double multiple=Math.pow(10,dec);
return Math.round(x*multiple)/multiple;
}V.V. -
U261B An Issue due to 3 Decimal Places in Percentage - Help Required
I've an Issue in BEX report output, which is like when I try to create a 'Percentage' computation on a Key Figure Value, I'm getting 3 decimal places as 'default' output.
The 'Calculations' settings I made for this KF is
> Calculate Result as ... Nothing Defined
> Calculate Single Values as .... Normalize According to Next Group Level Result
> [✔] Apply to results
> Calculation Direction - Along Rows
☹ I ran SAP_RSADMIN_MAINTAIN and set object 'IGNORE_T006_ANDEC' to the value 'X' - Not woking! Should I choose Update/Insert/Delete??
☹ T006-ANDEC & T006-DECAN for '%' has 0 decimal places only. Am I checking the correct stuff?
☹ OSS note 866505 not helpful for my issue. BW 7.0 Stack
I'm getting my output as expected, but the only worrying factor is 3 decimal places due to the 'Calculations'. I'm unable to resolve using existing methods. Should I raise an OSS Note for this?
Please help...Hi, I posted a message to SAP on this topic and got an explanation - it is a behaviour that cannot be changed in certain cases:
it is the known design that it is always displayed with three decimal
places for normalized values and the setting in Query Designer for
decimal place doesn't take effect. This is because that normalization
changes the number dimension of this structure element.
You may refer to below notes about more details.
> 869135 Decimal places and scaling for "Calculate Single Values As"
You cannot set the number of decimal places or the scaling for some
columns or structural components.
For 2: Some "Calculate As" functions change the number dimension of a
KID. In this case, the scaling and the number of decimal places set for
the KID are no longer relevant. In this case, the system ignores the
original setting and selects a setting that corresponds to the new
number dimension. This cannot be overwritten. The following functions
are affected:
Calculate Single Values as Scale to Result, Overall Result or Query
Result: Scaling 1 and three decimal places.
> 501930 Number of decimal places setting is not applied
As a result, normalized values resulting from the list calculation are
displayed with three decimal places and without scaling by default.
best regards, thom -
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.
Maybe you are looking for
-
I want to delite all adresses in my iCloud. how to do this?
i want to deliteall addresses in my icloud. how to do this???
-
HP 8150N Printer still not working with Snow Leopard
I went to the Hewlett Packard page for a new driver and was told the new driver for my printer was included in the Snow Leopard update. I'm sure it is, but my computer can't find the printer. I've used advice from other discussions and tried what I c
-
SPRY ALBUM GALLERY not working in IE7
Hi, I have created a spry album gallery using adobe's sample code and have test via dreamweaver - firefox 3.0 & IE7 to view the site. It works a treat. I have uploaded the files and now running live. One problem. I have type the web address into IE7
-
Which is better the 1st g or 2nd generation ipod touch
I like to know which is better and last longer and wont have much issues A. 1st g ipod touch or B. 2nd genertion ipof touch I like to know I dont know which one I want, and I like to hear it from a person who know what there talking about and who kno
-
POs value exceeding overall budget in WBS
Hello I'm an auditor in a multinational company that uses SAP. I have came upon a case in which the overal budget for a WBS is 100,000 and the total value of the POs opened against this WBS is around 140,000. Invoices recorded against these POs are l