473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert string to double ..please help

58 New Member
How to convert string to double?

Ive got a double variable dTot;
its value is 5.037717235E7
when i did FreemarkerTools .formatDecimal( dTot) i got it as string "50377172.3 5".

now i want to pass it as a double value to the method format() which is shown below.
when i do Double.parseDou ble i get dTot as 5.037717235E7
CurrencyConvert er.format(Doubl e.parseDouble(F reemarkerTools. formatDecimal(d Tot)));



what else can i do to pass it as 50377172.35 to the method format()







public class CurrencyConvert er {

public static String format(double n) {
if(n<0)
return "("+formatAcc(M ath.abs(n))+")" ;


return formatAcc(n);
}

public static String formatAcc(doubl e n){
//long decPart=0;
String s1 = ""+n;
String[] nums = s1.split("\\.") ;
long decPart = Integer.parseIn t(nums[1]);


// long decPart = (long) ((n-Math.floor(n))* 100);


if(n==0)
return "0.00";

int arr[] = new int[] { 1000, 100, 100, 100, 100, 100 };
String arrFromat[] = new String[] { "000", "00", "00", "00", "00",
"00" };
String s = "";
for (int i = 0; i < arr.length; i++) {
long x = (long) (n % arr[i]);
if (s.length() > 0)
s = "," + s;
n = n / arr[i];

if (n < 1) {
s = x + s;
break;
} else {
s = format(x, arrFromat[i]) + s;
}
}

return s+"."+format(de cPart,"00");
}


private static String format(long n, String format) {
String temp = n + "";
temp = format.substrin g(temp.length() ) + temp;
return temp;
}

public static void main(String[] args) {
System.out.prin tln(CurrencyCon verter.format(5 54406000.40));
}
}
Mar 13 '07
15 7659
shiniskumar
58 New Member
Use it like that for calculations. You will get the correct result.

Which calculation are you getting problems with it?
after splitting i get the decimal part as 355434664e7
when taking parseInt() of this i get error
long decPart = Integer.parseIn t(nums[1]);
Mar 13 '07 #11
r035198x
13,262 MVP
after splitting i get the decimal part as 355434664e7
when taking parseInt() of this i get error
long decPart = Integer.parseIn t(nums[1]);
Do not split the double, split the String.

Now look here my friend.

You have your number as a string as "55440600.4 0".
Pass it to the function like that as a String. So your function becomes

Expand|Select|Wrap|Line Numbers
  1.  public void myFunction(String value) { 
  2.     //Now split the String value
  3.     String[] values = value.split("\\.");
  4.     //Then do your parseLong or parseInt on the values of the array 
  5.     //If you need to do calculations using the value, then change it to
  6.     //double using parseDouble
  7.  
Now where do you not understand?
Mar 13 '07 #12
shiniskumar
58 New Member
Do not split the double, split the String.

Now look here my friend.

You have your number as a string as "55440600.4 0".
Pass it to the function like that as a String. So your function becomes

Expand|Select|Wrap|Line Numbers
  1.  public void myFunction(String value) { 
  2.     //Now split the String value
  3.     String[] values = value.split("\\.");
  4.     //Then do your parseLong or parseInt on the values of the array 
  5.     //If you need to do calculations using the value, then change it to
  6.     //double using parseDouble
  7.  
Now where do you not understand?

got it correctly when i did parseLong instead of parseInt.

Thankyou very much
Mar 13 '07 #13
r035198x
13,262 MVP
got it correctly when i did parseLong instead of parseInt.

Thankyou very much
Great! I hope everything is now working fine.
Mar 13 '07 #14
misguidedcoder
2 New Member
how to handle "ü" character is jsp???


can neone help...urgent help required
Mar 13 '07 #15
r035198x
13,262 MVP
how to handle "ü" character is jsp???


can neone help...urgent help required
You really should start your thread for that.
It is considered rude to hijack others' threads.
Mar 13 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
47073
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
3
2316
by: jeff_zhang446 | last post by:
Hi, I try to convert double to string as below: std::string cnvrtToString(double lValue) { std::ostringstream lStream; lStream << lValue; return lStream.str();
1
5418
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but I can;t convert the image. I certainly don't want to upload it the the server filesystem, convert...
17
4382
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
6
1407
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function declaration statments (first lines) e.g. Public Function ConvertCurrencyToEnglish(ByVal MyNumber As Double) As String Private Function ConvertHundreds(ByVal MyNumber As String) As String etc.
5
8598
by: yekasi | last post by:
Hi, I have this number, 1.5283632704970307 in char*, and I need to convert it to a double type in C++ that is capable of storing that number of precisions.... I tried doing atof and storing it to a double type. it came back with 6 digits precision only. I also have this number, 1159964886109, in char*, and I need to convert it to uint64... i did a atol, it converted it to a 2147483647, which truncated 4 bytes for me...
8
3945
by: shiniskumar | last post by:
Ive got a double variable dTotal =5.037717235E7 i formatted it using deciFormat.format(dTotal) and got the String value of dTotal=50377172.35 now i have to pass this value as an argument to a function convert(double num); how can i convert the string value 50377172.35 to double?
9
12105
by: =?Utf-8?B?Qnlyb24=?= | last post by:
How do you convert a hex string into a double using C# in framework v2.0? I've seen this question answered before, but apparently something has changed in 2.0 that negates the old solution that I've seen. The code: DoubleVariable = Double.Parse(HexString, NumberStyles.AllowHexSpecifier); results in the error: "The number style AllowHexSpecifier is not supported on floating point data
22
11791
by: xiao | last post by:
Can I fullfill this task? Using fred and fwrite?
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.