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
C# |
The user enter, for example, 22
and the second screen, I can display as I want:
22.00 with the following code
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

FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 1:59 PM EST
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.
FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 9:29 AM EST
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
}
Suthish NairRank #92 · 22.8K reputationPosted Feb 1, 2011, 9:30 AM EST
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Globalization;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); NumberStyles styles = NumberStyles.Number | NumberStyles.AllowCurrencySymbol; Double number = Double.Parse("$96,000.00", styles); Console.WriteLine(number); Console.ReadLine(); } } }aspkiddy17 reputationPosted Feb 1, 2011, 10:09 AM EST
I have a Compiler Error Message: CS1513: } expected Line 116
Line 114: Line 115: decimal amountD = s.MontantContribution; Line 116: mAmountLabel.Text = Convert.String(convertToCents(amountD)); Line 117: public int convertToCents(decimal d) Line 118: {int amountBest = Convert.ToInt32(d * 100); //line 119
return amountBest;//2200 cents //line 120
}//line 121
Suthish NairRank #92 · 22.8K reputationPosted Feb 1, 2011, 10:43 AM EST
FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 11:16 AM EST
aspkiddy17 reputationPosted Feb 1, 2011, 11:44 AM EST
Line 117: Line 118: decimal amountD = s.MontantContribution; Line 119: mAmountLabel.Text = Convert.String(convertToCents(amountD)); Line 120: public int convertToCents(decimal d) Line 121: {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
}
//*****************************************************
}
FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 12:08 PM EST
{
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
}
aspkiddy17 reputationPosted Feb 1, 2011, 12:35 PM EST
Line 120: // mAmountLabel.Text = Convert.String(convertToCents(amountD));// uncomment if not work Line 121: Line 122: mAmountLabel.Text = Convert.String(convertToCents(s.MontantContribution));// comment if not work Line 123: Line 124: public int convertToCents(decimal d)// separate methodwith : 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
}
//*****************************************************
}
FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 12:39 PM EST
FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 1:24 PM EST
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
}
aspkiddy17 reputationPosted Feb 1, 2011, 1:32 PM EST
I have a Compiler Error Message: CS0117: 'System.Convert' does not contain a definition for 'String' (Line 110)
Source Error:
Line 108: Line 109: decimal amountD = Convert.ToDecimal(s.MontantContribution);//assuming s.MontantContribution is string Line 110: mAmountLabel.Text = Convert.String(convertToCents(amountD)); Line 111: Line 112:FroglegRank #1,020 · 1.9K reputationPosted Feb 1, 2011, 1:41 PM EST
too quick at copy paste
Convert.ToString
aspkiddy17 reputationPosted Feb 1, 2011, 1:47 PM EST
Line 173: Line 174: Line 175: string strParametre = "?MTQ," + strIdTYerminal + ",TC27,T2M" + s.CCNumber + "=" + s.CCExpiry + "0?,A1" + Convert.ToString(convertToCents(amountD)) + ",DT" + DateTime.Now.ToString("MMddyyyyHHmm"); Line 176:aspkiddy17 reputationPosted Feb 1, 2011, 1:53 PM EST
I think, it's ok.... take me five min for testing