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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aspkiddy
    New Member
    • Jul 2010
    • 5

    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
    Code:
     
    private void SetPageState()
    		{
    		 int amountInt = int.Parse(mamountTextBox.Text);
    		 mFormPageState.AmountContribution = amountInt.ToString("0.00");
    
    		SavePageState();
    		}
    
    
    		public struct FormPageState
    		{
    
    		//public int amountInt;
    
    		public string AmountContribution;
    		}
    The user enter, for example, 22

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

    22.00 with the following code

    Code:
     
    mAmountLabel.Text = s.AmountContribution;
    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
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    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?

    Comment

    • aspkiddy
      New Member
      • Jul 2010
      • 5

      #3
      I have a solution...

      It works

      Code:
      private FormConfirmationPageState mFormConfirmationPageState;
      
      
                  
                  string cost;
                  int newVal;
      
      
      private void LoadLabels()
      		{
      			object FormPageState = Session["FormPage"];
      			totoForm.FormPageState s = (totoForm.FormPageState)FormPageState;
      
      
      
      
      
      			mMontantLabel.Text = s.MontantContribution;//  for  10.00
      
      
                  
      			cost = s.MontantContribution;
      			double doubleVal = 0.0;
      			if (Double.TryParse(cost, out doubleVal))
      			{
      			newVal = (int)doubleVal * 100;
      			mPriceLabel.Text = newVal.ToString();   //for :  1000
                       
      
      			}
      
      		}
      
      
      
      // (....)
      
      		{
      
      		SW.WriteLine(newVal.ToString() + ";" + DateTime.Now.ToString("yyyy'/'MM'/'dd' - 'HH':'mm':'ss") + ";");
      										SW.Close();
      		}

      Comment

      Working...