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
|
The user enter, for example, 22
and the second screen, I can display as I want:
22.00 with the following code
|
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
FroglegPosted Feb 1, 2011, 6:59 PM
Put
decimal amountD ;
at top of class outside of a method -- search this site for methods so you have a better understanding.
change
decimal amountD = Convert.ToDecimal(s.MontantContribution);//assuming s.MontantContribution is string
to
amountD = Convert.ToDecimal(s.MontantContribution);//assuming s.MontantContribution is string
Make sure s.MontantContribution is not null
I think you need to create an easier learning project to get the basics.
aspkiddyPosted Feb 1, 2011, 6:53 PM
I think, it's ok.... take me five min for testing
aspkiddyPosted Feb 1, 2011, 6:47 PM
FroglegPosted Feb 1, 2011, 6:41 PM
too quick at copy paste
Convert.ToString
aspkiddyPosted Feb 1, 2011, 6:32 PM
I have a Compiler Error Message: CS0117: 'System.Convert' does not contain a definition for 'String' (Line 110)
Source Error:
FroglegPosted Feb 1, 2011, 6:24 PM
try this
private void LoadLabels()
{
object FormPageState = Session["FormPage"];
DonationForm.FormPageState s = (DonationForm.FormPageState)FormPageState;
mPrenomNomLabel.Text = s.FirstName + " " + s.LastName;
mAddressLabel.Text = s.Address1 + " ; "+ s.Address2;
mLieuLabel.Text = s.City + " ; " + s.State ;
mPostalCode.Text = s.PostalCode;
mEmailLabel.Text = s.Email;
mTelLabel.Text = s.AreaCode + " " + s.PhoneNumber1 + " - "+ s.PhoneNumber2 ;
mMontantLabel.Text = s.MontantContribution;
decimal amountD = Convert.ToDecimal(s.MontantContribution);//assuming s.MontantContribution is string
mAmountLabel.Text = Convert.String(convertToCents(amountD));
mRecuImpotLabel.Text = s.RecuImpot;
messageRecuLabelEmail.Text = s.messageRecu; // pour confirmation d email
messageRecuLabelAlerte.Text = s.messageRecuAlerte; // pour alerte email
}
public int convertToCents(decimal d)// separate method
{
int newVal = Convert.ToInt32(d * 100);
return newVal;//2200 cents
}
FroglegPosted Feb 1, 2011, 5:39 PM
aspkiddyPosted Feb 1, 2011, 5:35 PM
with : private void LoadLabels()
{
object FormPageState = Session["FormPage"];
DonationForm.FormPageState s = (DonationForm.FormPageState)FormPageState;
mPrenomNomLabel.Text = s.FirstName + " " + s.LastName;
mAddressLabel.Text = s.Address1 + " ; "+ s.Address2;
mMontantLabel.Text = s.MontantContribution;
//*****************************************************
// decimal amountD = s.MontantContribution;//assume both decimals// uncomment if not work
// mAmountLabel.Text = Convert.String(convertToCents(amountD));// uncomment if not work
mAmountLabel.Text = Convert.String(convertToCents(s.MontantContribution));// comment if not work
public int convertToCents(decimal d)// separate method
{
int newVal = Convert.ToInt32(d * 100);
return newVal;//2200 cents
}
//*****************************************************
}
2nd test with comment of line 122
Compiler Error Message: CS1513: } expected
with private void LoadLabels()
{
object FormPageState = Session["FormPage"];
DonationForm.FormPageState s = (DonationForm.FormPageState)FormPageState;
mPrenomNomLabel.Text = s.FirstName + " " + s.LastName;
mAddressLabel.Text = s.Address1 + " ; "+ s.Address2;
mMontantLabel.Text = s.MontantContribution;
//*****************************************************
// decimal amountD = s.MontantContribution;//assume both decimals// uncomment if not work
// mAmountLabel.Text = Convert.String(convertToCents(amountD));// uncomment if not work
// mAmountLabel.Text = Convert.String(convertToCents(s.MontantContribution));// comment if not work
public int convertToCents(decimal d)// separate method
{
int newVal = Convert.ToInt32(d * 100);
return newVal;//2200 cents
}
//*****************************************************
}
FroglegPosted Feb 1, 2011, 5:08 PM
{
object FormPageState = Session["FormPage"];
DonationForm.FormPageState s = (DonationForm.FormPageState)FormPageState;
mPrenomNomLabel.Text = s.FirstName + " " + s.LastName;
mAddressLabel.Text = s.Address1 + " ; "+ s.Address2;
mMontantLabel.Text = s.MontantContribution;
// decimal amountD = s.MontantContribution;//assume both decimals// uncomment if not work
// mAmountLabel.Text = Convert.String(convertToCents(amountD));// uncomment if not work
mAmountLabel.Text = Convert.String(convertToCents(s.MontantContribution));// comment if not work
}
public int convertToCents(decimal d)// separate method
{
int newVal = Convert.ToInt32(d * 100);
return newVal;//2200 cents
}
aspkiddyPosted Feb 1, 2011, 4:44 PM
private void LoadLabels()
{
object FormPageState = Session["FormPage"];
DonationForm.FormPageState s = (DonationForm.FormPageState)FormPageState;
mPrenomNomLabel.Text = s.FirstName + " " + s.LastName;
mAddressLabel.Text = s.Address1 + " ; "+ s.Address2;
mMontantLabel.Text = s.MontantContribution;
//*****************************************************
decimal amountD = s.MontantContribution;
mAmountLabel.Text = Convert.String(convertToCents(amountD));
public int convertToCents(decimal d)
{
int newVal = Convert.ToInt32(d * 100);
return newVal;//2200 cents
}
//*****************************************************
}
FroglegPosted Feb 1, 2011, 4:16 PM
Suthish NairPosted Feb 1, 2011, 3:43 PM
aspkiddyPosted Feb 1, 2011, 3:09 PM
I have a Compiler Error Message: CS1513: } expected Line 116
int amountBest = Convert.ToInt32(d * 100); //line 119
return amountBest;//2200 cents //line 120
}//line 121
Suthish NairPosted Feb 1, 2011, 2:30 PM
FroglegPosted Feb 1, 2011, 2:29 PM
decimal amountD = 22.00m;//$22
mAmountLabel.Text = Convert.String(convertToCents(amountD);
public int convertToCents(decimal d)
{
int i = Convert.ToInt32(d * 100);
return i;//2200 cents
}