468,272 Members | 2,039 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

How to convert from dollars to cents (for example 22.00) to 2000 with no decimal?

Amount text box...
the number is positive and this field should be sent as cents ( $22.00 should be sent as 2200 with no decimal).

How can I ?

in my first form page (where there is a textbox/ field )

I use
Expand|Select|Wrap|Line Numbers
  1.  
  2. private void SetPageState()
  3.         {
  4.          int amountInt = int.Parse(mamountTextBox.Text);
  5.          mFormPageState.AmountContribution = amountInt.ToString("0.00");
  6.  
  7.         SavePageState();
  8.         }
  9.  
  10.  
  11.         public struct FormPageState
  12.         {
  13.  
  14.         //public int amountInt;
  15.  
  16.         public string AmountContribution;
  17.         }
  18.  
The user enter, for example, 22

and the second screen, I can display as I want:

22.00 with the following code

Expand|Select|Wrap|Line Numbers
  1.  
  2. mAmountLabel.Text = s.AmountContribution;
  3.  
  4.  
  5.  
So I must transform this number (for example 22.00) to 2000 with no decimal for sending on the transaction server


How can I ? could you help me please
Feb 1 '11 #1

✓ answered by aspkiddy

I have a solution...

It works

Expand|Select|Wrap|Line Numbers
  1. private FormConfirmationPageState mFormConfirmationPageState;
  2.  
  3.  
  4.  
  5.             string cost;
  6.             int newVal;
  7.  
  8.  
  9. private void LoadLabels()
  10.         {
  11.             object FormPageState = Session["FormPage"];
  12.             totoForm.FormPageState s = (totoForm.FormPageState)FormPageState;
  13.  
  14.  
  15.  
  16.  
  17.  
  18.             mMontantLabel.Text = s.MontantContribution;//  for  10.00
  19.  
  20.  
  21.  
  22.             cost = s.MontantContribution;
  23.             double doubleVal = 0.0;
  24.             if (Double.TryParse(cost, out doubleVal))
  25.             {
  26.             newVal = (int)doubleVal * 100;
  27.             mPriceLabel.Text = newVal.ToString();   //for :  1000
  28.  
  29.  
  30.             }
  31.  
  32.         }
  33.  
  34.  
  35.  
  36. // (....)
  37.  
  38.         {
  39.  
  40.         SW.WriteLine(newVal.ToString() + ";" + DateTime.Now.ToString("yyyy'/'MM'/'dd' - 'HH':'mm':'ss") + ";");
  41.                                         SW.Close();
  42.         }
  43.  
  44.  

2 12432
GaryTexmo
1,501 Expert 1GB
Correct me if I'm wrong here, but you'll only have two decimal places, correct? If that's the case, just multiply by 100 and cast it to an integer.

Would that work?
Feb 1 '11 #2
I have a solution...

It works

Expand|Select|Wrap|Line Numbers
  1. private FormConfirmationPageState mFormConfirmationPageState;
  2.  
  3.  
  4.  
  5.             string cost;
  6.             int newVal;
  7.  
  8.  
  9. private void LoadLabels()
  10.         {
  11.             object FormPageState = Session["FormPage"];
  12.             totoForm.FormPageState s = (totoForm.FormPageState)FormPageState;
  13.  
  14.  
  15.  
  16.  
  17.  
  18.             mMontantLabel.Text = s.MontantContribution;//  for  10.00
  19.  
  20.  
  21.  
  22.             cost = s.MontantContribution;
  23.             double doubleVal = 0.0;
  24.             if (Double.TryParse(cost, out doubleVal))
  25.             {
  26.             newVal = (int)doubleVal * 100;
  27.             mPriceLabel.Text = newVal.ToString();   //for :  1000
  28.  
  29.  
  30.             }
  31.  
  32.         }
  33.  
  34.  
  35.  
  36. // (....)
  37.  
  38.         {
  39.  
  40.         SW.WriteLine(newVal.ToString() + ";" + DateTime.Now.ToString("yyyy'/'MM'/'dd' - 'HH':'mm':'ss") + ";");
  41.                                         SW.Close();
  42.         }
  43.  
  44.  
Feb 2 '11 #3

Post your reply

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

Similar topics

reply views Thread by JimDuggan | last post: by
1 post views Thread by =?Utf-8?B?R3JlZyBH?= | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.