hi,
I have real value: 2,000.4 I want to show it like 2000.4
is there any function to do it?
hi,
I have real value: 2,000.4 I want to show it like 2000.4
is there any function to do it?
Use num2str():
num2str(yourNumber, 1, 1, DecimalSeparator::Dot, ThousandSeparator::None)
I show all context.
I want to insert item price to another database via ODBC. I prepare t-sql insert statement:
sqlStr = strfmt(“INSERT INTO [AOLPROD].[dbo].[INVENTTABLE] %1 VALUES %2”, fieldsStr, valueStr);
valueStr = (‘AC1208’, ‘Rzutnik Quantum Nobo 2521’, ‘NOBO’, 0.00, 2,789.10, ‘szt’)
price is real type but AX save it with comma.
I wrote below code but it doesn’t work. I get num with comma sign again:
priceStr = num2str(priceDiscShop.Amount, 1, 1, DecimalSeparator::Dot, ThousandSeparator::None);
price = str2num(priceStr);
Are you saying that num2str() doesn’t work? I wouldn’t believe so. Or do you actually use the price variable and the default conversion from real to string, instead of the formatted value in priceStr? That would be the bug.
I start from the beginning
I want to insert items price from AX database to another database AOLPROD. In AOLPROD I have table inventTable with coulmn price - type numeric(28,12).
To do it I use ax class with odbc connector.
problem:
For price AX formatting value so number 2000,50 AX show like 2,000.50. I build query using strfmt and odbc connector return error.
example value statment: VALUE (‘AC1208’, ‘Rzutnik Quantum Nobo 2521’, ‘NOBO’, 0.00, 2,789.10, ‘szt’) - there is two commas and mssql parser return error.
I used below function
priceStr = num2str(priceDiscShop.Amount, 1, 1, DecimalSeparator::Dot, ThousandSeparator::None);
I got 2000.5. It’s ok
but I can’t insert it because I need numeric type.
I used str2num function but I got again 2,000.50. Problem still exist.
In simple words I would like to delete comma from value.
First of all, writing data directly to an AX database is a very bad idea. Don’t do that! How will you deal with RecIds, for example? You should use AIF or Business Connector - they both go through AOS and apply AX business logic, including things like security, logging, virtual companies etc.
If you convert a real to string and back to real, you actually did completely nothing - you still have a real value, which doesn’t have any string format by itself. If you have troubles with the default formatting when converting a real to string, do the conversion by yourself with num2str(), as showed before.
I don’t what you mean by “can’t insert it because I need numeric type” if you’re actual constructing a string SQL command (sqlStr = strfmt(“INSERT INTO [AOLPROD].[dbo].[INVENTTABLE] %1 VALUES %2”, fieldsStr, valueStr)).
I show you all method:
odbcHandler = ODBCHandler_ART::construct();
odbcHandler.init();
odbcHandler.executeInsertOrUpdate(“DELETE FROM [AOLPROD].[dbo].[INVENTTABLE]”);
invDim.clear();
invDim.InventLocationId = ‘WMS’;
invDim = InventDim::findOrCreate(invDim);
fieldsStr = “(ITEMID, ITEMNAME, ITEMBRAND, AVAILPHYSICAL, AMOUNT, UNITID)”;
while select invSum
join invTable
where invTable.ItemId == invSum.ItemId
&& invSum.InventDimId == invDim.InventDimId
&& invTable.ShowInAol_ART == NoYes::Yes
{
priceDiscShop.clear();
priceDiscShop = PriceDiscTableShopIntegration_ART::find(invSum.ItemId);
availPysical = invTable.availPhysicalAOL_ART();
//availPysical = str2num(availPhyStr);
price = 0;
valueStr = strfmt("(’%1’, ‘%2’, ‘%3’, %4, %5, ‘%6’)", invTable.ItemId, strReplace(invTable.ItemName, “’”, “”), invTable.ItemBrand_RS, availPysical,
price, priceDiscShop.SalesUnit);
sqlStr = strfmt(“INSERT INTO [AOLPROD].[dbo].[INVENTTABLE] %1 VALUES %2”, fieldsStr, valueStr);
odbcHandler.executeInsertOrUpdate(sqlStr);
}
odbcHandler = ODBCHandler_ART::construct();
odbcHandler.init();
odbcHandler.executeInsertOrUpdate(“DELETE FROM [APP2DC1].[AOLPROD].[dbo].[INVENTTABLE]”);
invDim.clear();
invDim.InventLocationId = ‘WMS’;
invDim = InventDim::findOrCreate(invDim);
fieldsStr = “(ITEMID, ITEMNAME, ITEMBRAND, AVAILPHYSICAL, AMOUNT, UNITID)”;
while select invSum
join invTable
where invTable.ItemId == invSum.ItemId
&& invSum.InventDimId == invDim.InventDimId
&& invTable.ShowInAol_ART == NoYes::Yes
{
priceDiscShop.clear();
priceDiscShop = PriceDiscTableShopIntegration_ART::find(invSum.ItemId);
availPysical = invTable.availPhysicalAOL_ART();
availPysical = str2num(availPhyStr);
valueStr = strfmt("(’%1’, ‘%2’, ‘%3’, %4, %5, ‘%6’)", invTable.ItemId, strReplace(invTable.ItemName, “’”, “”), invTable.ItemBrand_RS, availPysical,
price, priceDiscShop.SalesUnit);
sqlStr = strfmt(“INSERT INTO [APP2DC1].[AOLPROD].[dbo].[INVENTTABLE] %1 VALUES %2”, fieldsStr, valueStr);
odbcHandler.executeInsertOrUpdate(sqlStr);
}
I pasted whole method.