code syntax remove comma from decimal

RKM
Member Posts: 26
need to convert 1,376 to 1376 in one line of code
I am using a variable getvalue = 1,376
can someone give me guidance
RKM
I am using a variable getvalue = 1,376
can someone give me guidance
RKM
1
Comments
-
pseudocode should look similar to this:
tVar := FORMAT(1,376) //convert to text var
DELSTR(tVar, StrPos(tVar,','),1)
EVALUATE(dVar,tVar); //convert back to decimal
//Result should be 13761 -
Text := FORMAT(YourDecimal,0,1);
It will create text string from the decimal without thousand separator (standard format 1)3 -
When I EVALUATE this amount example
tvar :=FORMAT(Amount);
tvar :=DELSTR( tvar, STRPOS( tvar,','),1);
EVALUATE(Amount,tvar);
how do I pass Amount in new format to a codeunit??0 -
Hi:
I have the same problem with C/SIDE. I need to turn string to numerico and in the documentation I have not found any function to be able to make it.
Thanks beforehand.
A greeting, Juan.RKM wrote:When I EVALUATE this amount example
tvar :=FORMAT(Amount);
tvar :=DELSTR( tvar, STRPOS( tvar,','),1);
EVALUATE(Amount,tvar);
how do I pass Amount in new format to a codeunit??0 -
This problem I have faced a lot of times, and always it differed somewhat from the previous times. So I created a function that can handle all.
Function String2Decimal(ptexString : Text[250];ptexFormat : Text[250];PtexDecimalSign : Text[1]) PdecReturnValue : Decimal // String2Decimal // Receives a string and a format and converts that to a decimal // If a decimal sign is put into the string, then the rest of the size is not important, // the right side is considered the decimal part, the left side is considered the integer part. // The format is not considered in that case. // Non-digit-characters are just filtered out ex: 'A5B6.D8R' => 56.8 // If no decimal sign is put into the string, the format is important and it is interpreted // FROM RIGHT TO LEFT (and not from left to right)!! // ex : '12345','IIIIIIDD' => 123.45 // ex2 : '12345','IDD' => 123.45 (the decimal digits are important, the rest is added when necessary) // PARAMETERS : // ptexString : the string to be converted // ptexFormat : the format of the string (if it is a normal number, with a decimal sign if necessary, // you can leave this parameter blank) // i : integer part // d : decimal part // . : decimal sign // PtexDecimalSign : ',' : decimal comma // '.' : decimal dot // other character : standard of Navision for decimal sign // RETURN-VALUE : the decimal or 0 if something was wrong with ptexString // // EX: (the point is always the current decimal sign in these examples!!) // '12345','II.DD' => 12.45 // '12345','IDD' => 123.45 // '12345','DD' => 123.45 // '12345','IIIIIIIDD',123.45 // '12345','' => 12345 // '-12345','' => -12345 // '12D3D4D5','' => 12345 // '12D3D4D5','I' => 12345 // '123.45','' => 123.45 // '123.45','III.DD' => 123.45 // '123.45','IID.DD' => 123.45 // '1,123.45','' => 1123.45 IF DELCHR(ptexFormat,'=','ID.') <> '' THEN ERROR(STRSUBSTNO(ltxcFormatNotCorrect,ptexFormat)); // determine thousand and decimal seperator IF (PtexDecimalSign <> ',') AND (PtexDecimalSign <> '.') THEN PtexDecimalSign := GetDecimalSign(); PdecReturnValue := 0; lblnNegative := FALSE; ltexIntegerPart := ''; ltexDecimalPart := ''; lint := NumEntries(ptexString,PtexDecimalSign); IF lint = 1 THEN BEGIN lintLen := STRLEN(ptexString); lintLen2 := STRLEN(ptexFormat); WHILE lintLen + lintLen2 > 0 DO BEGIN IF lintLen2 = 0 THEN BEGIN ltexIntegerPart := COPYSTR(ptexString,1,lintLen) + ltexIntegerPart; lintLen := 0; END ELSE IF lintLen = 0 THEN lintLen2 := 0 ELSE BEGIN CASE FORMAT(ptexFormat[lintLen2]) OF 'D': ltexDecimalPart := COPYSTR(ptexString,lintLen,1) + ltexDecimalPart; 'I': ltexIntegerPart := COPYSTR(ptexString,lintLen,1) + ltexIntegerPart; END; END; lintLen := lintLen - 1; lintLen2 := lintLen2 - 1; END; END ELSE BEGIN ltexIntegerPart := Entry(1,ptexString,PtexDecimalSign); ltexDecimalPart := Entry(2,ptexString,PtexDecimalSign); END; ltexIntegerPart := DELCHR(ltexIntegerPart,'=',DELCHR(ltexIntegerPart,'=','-+0123456789')); ltexDecimalPart := DELCHR(ltexDecimalPart,'=',DELCHR(ltexDecimalPart,'=','-+0123456789')); lintLen := STRLEN(ltexIntegerPart); FOR lint := 1 TO lintLen DO BEGIN CASE FORMAT(ltexIntegerPart[lint]) OF '-': lblnNegative := TRUE; '0'..'9': BEGIN EVALUATE(lintHelp,FORMAT(ltexIntegerPart[lint])); PdecReturnValue := PdecReturnValue * 10 + lintHelp; END; END; END; lintLen := STRLEN(ltexDecimalPart); FOR lint := 1 TO lintLen DO BEGIN CASE FORMAT(ltexDecimalPart[lint]) OF '-': lblnNegative := TRUE; '0'..'9': BEGIN EVALUATE(lintHelp,FORMAT(ltexDecimalPart[lint])); PdecReturnValue := PdecReturnValue + lintHelp * POWER(0.1,lint); END; END; END; IF lblnNegative THEN PdecReturnValue := - PdecReturnValue;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions