Developer forum

Forum » Development » Importing double values using the API

Importing double values using the API

Lars Hejgaard Sørensen
Reply
Hi,

I have an routine that imports products using the API. On the products I have some custom fields, including a field of type float to store a custom price, however, importing figures with decimals to this field has a somewhat undesired sideeffect in that it multiplies this figure by 100. "Easy, you mig say, just as I did, but now I've tried every thinkable way, but nothing seems to be working. Multiplying, and dividing, hardcoding the figures both with "," and "." as separator, but nothing works. I ended up with updating this field seperately using an SQL statement, after the product is saved, just to avoid outrageous prices on the website.
 
I was thinking, could there be a bug here? Saving the price works perfectly through the API, but I guess, that's handled in a different manner than saving a custom field value.

BR.
Lars

Replies

 
Vladimir
Reply
Hi Lars!
Did you use Import/Export module?
I'm can't repeat such situation on my local site (v19.2.3.5). Are you sure that the value is multiply by 100, or maybe it lost a separator?
Please write me the URL of your site, I'll check the settings.

Best regards,
Vladimir



 
Lars Hejgaard Sørensen
Reply
Hi Vladimir,

No, I create the products in C# using the API, not the module. I don't know if the number is miltiplied, or if the seperator is removed... I just feed the field with a double value:

field.Value = Base.ChkDouble(p.PriceWithVATDK);

By the way, I'm not receiving any notifications e-mails from the new forum.

BR.
Lars
 
Vladimir
Reply
Hi again)
I rummaged in the logs - it seems on 19.2.2.1 version such mistake was actually...
So can you update version?

Yeah, I know about the forum ( 

Best regards,
Vladimir



 
Lars Hejgaard Sørensen
Reply
Hi,

The solution is currently running 19.2.2.2. Could you verify that the bug is fixed here?

BR.
Lars

 
Steen Nørgaard Perdersen
Reply

Well - Base.ChkDouble and the likes are sensitive to environment settings. If they change, but you know the specific format you can do this:

System.Globalization.

 

 

{

CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture; string decimalSeparator = ci.NumberFormat.CurrencyDecimalSeparator;if(decimalSeparator==",")
...and handle the parsing accordingly.
 
Steen Nørgaard Perdersen
Reply

wow.... that didn't come out right. Trying plain text.

System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
string decimalSeparator = ci.NumberFormat.CurrencyDecimalSeparator;

if(decimalSeparator==",")
{

 

You must be logged in to post in the forum