PayPal Developer Issues With Comma
I have run into an error. I am using https://developer.paypal.com/docs/checkout/integrate/ to implement the PayPal payment into my ASP.NET MVC Project. My currency is a float, and the project has prices like 150,99. Whenever this price goes through, it will say that the price is 99,00 EUR. It only reads what is behind the comma. Whenever the price is 190,00, it will correctly say that the price is 190,00 EUR. How do I fix this?
The JavaScript on the front-end is currently this:
<script>
var totalPrice = (@ViewBag.totalPrice);
</script>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
layout: 'horizontal', // horizontal | vertical
size: 'large', // medium | large | responsive
shape: 'pill', // pill | rect
color: 'black' // gold | blue | silver | white | black
},
// Specify allowed and disallowed funding sources
//
// Options:
// - paypal.FUNDING.CARD
// - paypal.FUNDING.CREDIT
// - paypal.FUNDING.ELV
funding: {
allowed: [
paypal.FUNDING.CARD,
paypal.FUNDING.CREDIT
],
disallowed:
},
// Enable Pay Now checkout flow (optional)
commit: true,
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<removed>',
production: '<insert production client id>'
},
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: totalPrice,
currency: 'EUR'
}
}
]
}
});
},
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
And back-end for the price is like this:
[HttpGet]
public IActionResult Index()
{
...
float totalPrice = 0;
float sendcost = 2.95f;
...
foreach(ShoppingCartModel item in model)
{
item.subtotal = item.qty * item.price;
totalPrice += item.subtotal;
}
if(totalPrice < 100)
{
ViewBag.totalPrice = totalPrice + sendcost;;
}
else
{
ViewBag.totalPrice = totalPrice;
}
}
}
...
}
javascript c# asp.net-mvc paypal
|
show 3 more comments
I have run into an error. I am using https://developer.paypal.com/docs/checkout/integrate/ to implement the PayPal payment into my ASP.NET MVC Project. My currency is a float, and the project has prices like 150,99. Whenever this price goes through, it will say that the price is 99,00 EUR. It only reads what is behind the comma. Whenever the price is 190,00, it will correctly say that the price is 190,00 EUR. How do I fix this?
The JavaScript on the front-end is currently this:
<script>
var totalPrice = (@ViewBag.totalPrice);
</script>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
layout: 'horizontal', // horizontal | vertical
size: 'large', // medium | large | responsive
shape: 'pill', // pill | rect
color: 'black' // gold | blue | silver | white | black
},
// Specify allowed and disallowed funding sources
//
// Options:
// - paypal.FUNDING.CARD
// - paypal.FUNDING.CREDIT
// - paypal.FUNDING.ELV
funding: {
allowed: [
paypal.FUNDING.CARD,
paypal.FUNDING.CREDIT
],
disallowed:
},
// Enable Pay Now checkout flow (optional)
commit: true,
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<removed>',
production: '<insert production client id>'
},
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: totalPrice,
currency: 'EUR'
}
}
]
}
});
},
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
And back-end for the price is like this:
[HttpGet]
public IActionResult Index()
{
...
float totalPrice = 0;
float sendcost = 2.95f;
...
foreach(ShoppingCartModel item in model)
{
item.subtotal = item.qty * item.price;
totalPrice += item.subtotal;
}
if(totalPrice < 100)
{
ViewBag.totalPrice = totalPrice + sendcost;;
}
else
{
ViewBag.totalPrice = totalPrice;
}
}
}
...
}
javascript c# asp.net-mvc paypal
In the example code in the docs, all the prices are formatted like'150.99'
, what's the final output ofvar totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?
– Chris G
Nov 20 at 23:37
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at thetotal
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output ofvar totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.
– floorvmt
Nov 21 at 0:02
By final output I mean what the source code looks like in your browser. I'm going to assume it'svar totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use.
in their floats. So if you end up with'150,99'
, you just need toreplace()
the comma with a period.
– Chris G
Nov 21 at 10:07
1
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next tovar totalPrice =
?
– Chris G
Nov 21 at 13:33
1
Right, that's what's causing this.(443)
evaluates to443
, but(150,99)
evaluates to99
see here The quick and dirty fix isvar totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.
– Chris G
Nov 21 at 14:06
|
show 3 more comments
I have run into an error. I am using https://developer.paypal.com/docs/checkout/integrate/ to implement the PayPal payment into my ASP.NET MVC Project. My currency is a float, and the project has prices like 150,99. Whenever this price goes through, it will say that the price is 99,00 EUR. It only reads what is behind the comma. Whenever the price is 190,00, it will correctly say that the price is 190,00 EUR. How do I fix this?
The JavaScript on the front-end is currently this:
<script>
var totalPrice = (@ViewBag.totalPrice);
</script>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
layout: 'horizontal', // horizontal | vertical
size: 'large', // medium | large | responsive
shape: 'pill', // pill | rect
color: 'black' // gold | blue | silver | white | black
},
// Specify allowed and disallowed funding sources
//
// Options:
// - paypal.FUNDING.CARD
// - paypal.FUNDING.CREDIT
// - paypal.FUNDING.ELV
funding: {
allowed: [
paypal.FUNDING.CARD,
paypal.FUNDING.CREDIT
],
disallowed:
},
// Enable Pay Now checkout flow (optional)
commit: true,
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<removed>',
production: '<insert production client id>'
},
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: totalPrice,
currency: 'EUR'
}
}
]
}
});
},
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
And back-end for the price is like this:
[HttpGet]
public IActionResult Index()
{
...
float totalPrice = 0;
float sendcost = 2.95f;
...
foreach(ShoppingCartModel item in model)
{
item.subtotal = item.qty * item.price;
totalPrice += item.subtotal;
}
if(totalPrice < 100)
{
ViewBag.totalPrice = totalPrice + sendcost;;
}
else
{
ViewBag.totalPrice = totalPrice;
}
}
}
...
}
javascript c# asp.net-mvc paypal
I have run into an error. I am using https://developer.paypal.com/docs/checkout/integrate/ to implement the PayPal payment into my ASP.NET MVC Project. My currency is a float, and the project has prices like 150,99. Whenever this price goes through, it will say that the price is 99,00 EUR. It only reads what is behind the comma. Whenever the price is 190,00, it will correctly say that the price is 190,00 EUR. How do I fix this?
The JavaScript on the front-end is currently this:
<script>
var totalPrice = (@ViewBag.totalPrice);
</script>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
// Render the PayPal button
paypal.Button.render({
// Set your environment
env: 'sandbox', // sandbox | production
// Specify the style of the button
style: {
layout: 'horizontal', // horizontal | vertical
size: 'large', // medium | large | responsive
shape: 'pill', // pill | rect
color: 'black' // gold | blue | silver | white | black
},
// Specify allowed and disallowed funding sources
//
// Options:
// - paypal.FUNDING.CARD
// - paypal.FUNDING.CREDIT
// - paypal.FUNDING.ELV
funding: {
allowed: [
paypal.FUNDING.CARD,
paypal.FUNDING.CREDIT
],
disallowed:
},
// Enable Pay Now checkout flow (optional)
commit: true,
// PayPal Client IDs - replace with your own
// Create a PayPal app: https://developer.paypal.com/developer/applications/create
client: {
sandbox: '<removed>',
production: '<insert production client id>'
},
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: totalPrice,
currency: 'EUR'
}
}
]
}
});
},
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
window.alert('Payment Complete!');
});
}
}, '#paypal-button-container');
</script>
And back-end for the price is like this:
[HttpGet]
public IActionResult Index()
{
...
float totalPrice = 0;
float sendcost = 2.95f;
...
foreach(ShoppingCartModel item in model)
{
item.subtotal = item.qty * item.price;
totalPrice += item.subtotal;
}
if(totalPrice < 100)
{
ViewBag.totalPrice = totalPrice + sendcost;;
}
else
{
ViewBag.totalPrice = totalPrice;
}
}
}
...
}
javascript c# asp.net-mvc paypal
javascript c# asp.net-mvc paypal
edited Nov 21 at 16:14
Amy
21.5k1774131
21.5k1774131
asked Nov 20 at 23:31
floorvmt
829
829
In the example code in the docs, all the prices are formatted like'150.99'
, what's the final output ofvar totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?
– Chris G
Nov 20 at 23:37
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at thetotal
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output ofvar totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.
– floorvmt
Nov 21 at 0:02
By final output I mean what the source code looks like in your browser. I'm going to assume it'svar totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use.
in their floats. So if you end up with'150,99'
, you just need toreplace()
the comma with a period.
– Chris G
Nov 21 at 10:07
1
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next tovar totalPrice =
?
– Chris G
Nov 21 at 13:33
1
Right, that's what's causing this.(443)
evaluates to443
, but(150,99)
evaluates to99
see here The quick and dirty fix isvar totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.
– Chris G
Nov 21 at 14:06
|
show 3 more comments
In the example code in the docs, all the prices are formatted like'150.99'
, what's the final output ofvar totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?
– Chris G
Nov 20 at 23:37
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at thetotal
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output ofvar totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.
– floorvmt
Nov 21 at 0:02
By final output I mean what the source code looks like in your browser. I'm going to assume it'svar totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use.
in their floats. So if you end up with'150,99'
, you just need toreplace()
the comma with a period.
– Chris G
Nov 21 at 10:07
1
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next tovar totalPrice =
?
– Chris G
Nov 21 at 13:33
1
Right, that's what's causing this.(443)
evaluates to443
, but(150,99)
evaluates to99
see here The quick and dirty fix isvar totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.
– Chris G
Nov 21 at 14:06
In the example code in the docs, all the prices are formatted like
'150.99'
, what's the final output of var totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?– Chris G
Nov 20 at 23:37
In the example code in the docs, all the prices are formatted like
'150.99'
, what's the final output of var totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?– Chris G
Nov 20 at 23:37
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at the
total
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output of var totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.– floorvmt
Nov 21 at 0:02
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at the
total
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output of var totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.– floorvmt
Nov 21 at 0:02
By final output I mean what the source code looks like in your browser. I'm going to assume it's
var totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use .
in their floats. So if you end up with '150,99'
, you just need to replace()
the comma with a period.– Chris G
Nov 21 at 10:07
By final output I mean what the source code looks like in your browser. I'm going to assume it's
var totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use .
in their floats. So if you end up with '150,99'
, you just need to replace()
the comma with a period.– Chris G
Nov 21 at 10:07
1
1
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next to
var totalPrice =
?– Chris G
Nov 21 at 13:33
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next to
var totalPrice =
?– Chris G
Nov 21 at 13:33
1
1
Right, that's what's causing this.
(443)
evaluates to 443
, but (150,99)
evaluates to 99
see here The quick and dirty fix is var totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.– Chris G
Nov 21 at 14:06
Right, that's what's causing this.
(443)
evaluates to 443
, but (150,99)
evaluates to 99
see here The quick and dirty fix is var totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.– Chris G
Nov 21 at 14:06
|
show 3 more comments
1 Answer
1
active
oldest
votes
The official answer is that your web app's language setting causes the server to output numerical values with a comma as decimal separator. So
var totalPrice = (@ViewBag.totalPrice);
ends up
var totalPrice = (150,99);
in the browser and since JavaScript has something called a comma operator, totalPrice
is now 99
.
To fix this on the server side, you can change the locale used for formatting to English by adding
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US");
to the Configure()
method in Startup.cs
.
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using theSingle.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter
– Stijn
Nov 21 at 16:26
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403183%2fpaypal-developer-issues-with-comma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The official answer is that your web app's language setting causes the server to output numerical values with a comma as decimal separator. So
var totalPrice = (@ViewBag.totalPrice);
ends up
var totalPrice = (150,99);
in the browser and since JavaScript has something called a comma operator, totalPrice
is now 99
.
To fix this on the server side, you can change the locale used for formatting to English by adding
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US");
to the Configure()
method in Startup.cs
.
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using theSingle.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter
– Stijn
Nov 21 at 16:26
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
add a comment |
The official answer is that your web app's language setting causes the server to output numerical values with a comma as decimal separator. So
var totalPrice = (@ViewBag.totalPrice);
ends up
var totalPrice = (150,99);
in the browser and since JavaScript has something called a comma operator, totalPrice
is now 99
.
To fix this on the server side, you can change the locale used for formatting to English by adding
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US");
to the Configure()
method in Startup.cs
.
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using theSingle.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter
– Stijn
Nov 21 at 16:26
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
add a comment |
The official answer is that your web app's language setting causes the server to output numerical values with a comma as decimal separator. So
var totalPrice = (@ViewBag.totalPrice);
ends up
var totalPrice = (150,99);
in the browser and since JavaScript has something called a comma operator, totalPrice
is now 99
.
To fix this on the server side, you can change the locale used for formatting to English by adding
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US");
to the Configure()
method in Startup.cs
.
The official answer is that your web app's language setting causes the server to output numerical values with a comma as decimal separator. So
var totalPrice = (@ViewBag.totalPrice);
ends up
var totalPrice = (150,99);
in the browser and since JavaScript has something called a comma operator, totalPrice
is now 99
.
To fix this on the server side, you can change the locale used for formatting to English by adding
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US");
to the Configure()
method in Startup.cs
.
answered Nov 21 at 15:26
Chris G
5,9522821
5,9522821
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using theSingle.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter
– Stijn
Nov 21 at 16:26
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
add a comment |
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using theSingle.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter
– Stijn
Nov 21 at 16:26
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
1
1
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using the
Single.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter– Stijn
Nov 21 at 16:26
This should work, but it should be noted that changing the culture of all threads in the AppDomain could have other effects that are undesired. Another option is using the
Single.ToString(string format, IFormatProvider provider)
overload that accepts a culture as the second parameter– Stijn
Nov 21 at 16:26
1
1
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
Thanks @Stijn for the useful information! It did have some effects on other data in the server side if I tried to change the culture to en-US.
– floorvmt
Nov 29 at 16:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403183%2fpaypal-developer-issues-with-comma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In the example code in the docs, all the prices are formatted like
'150.99'
, what's the final output ofvar totalPrice = (@ViewBag.totalPrice);
? Have you tried using a period as decimal separator?– Chris G
Nov 20 at 23:37
@ChrisG In the JavaScript, I tried the inputs 20.99 and 20,99 at the
total
. And for 20.99 it correctly shows 20,99 EUR on the PayPal Payment view and when I enter 20,99, the payment screen doesn't appear. The final output ofvar totalPrice = (@ViewBag.totalPrice);
is any products price, which could be 20,99 or 20,00.– floorvmt
Nov 21 at 0:02
By final output I mean what the source code looks like in your browser. I'm going to assume it's
var totalPrice = '150,99';
since that's the only way to produce the issue I guess? Anyway, the problem is that English, and consequently all programming languages and APIs, use.
in their floats. So if you end up with'150,99'
, you just need toreplace()
the comma with a period.– Chris G
Nov 21 at 10:07
1
Sorry, I will ask you a third time: what is the final output? What does it say in your browser's source view next to
var totalPrice =
?– Chris G
Nov 21 at 13:33
1
Right, that's what's causing this.
(443)
evaluates to443
, but(150,99)
evaluates to99
see here The quick and dirty fix isvar totalPrice = parseFloat("@ViewBag.totalPrice".replace(",", "."));
but the proper fix is to set up your backend so floating point values are output using a period as decimal separator.– Chris G
Nov 21 at 14:06