Adding zeros to a variable..

I hav ea program that manipulates/works on six digit number entered by user.what i want is that if user enters less than 6 digits, program adds zeros at the end of number to make it 6 digit. like if user enters 241 program converts it into 241000 before manipulating it.which area i must look into? contecating or what?

Strings? Strings? We don' need no stinkin' Strings!
  while(x < 100000) x *= 10;this code works for all non-zero input that is actually 6 digits or less.
You didn't specify what you want to do for zero input, or negative input, or too long input. Here is some more robust code that works for all those cases, but you will need to check if it does what you want.
  int digitLimit = 1000000; // number of zeros here is number of digits.
  if(x<0){ // input was negative
    while(x <= -digitLimit){x /= 10;}
    x = -x; // done backwards to prevent failure on smallest possible negative number
  } else if (x = 0) { // input was zero
    x = 123456;
  } else if (x >= digitLimit) { // input was too big
    while(x >= digitLimit) {x /= 10;}  
  // this final pass deals with both small neg and small pos
  while(x < digitLimit/10){x *= 10;}

Similar Messages

  • (ADI) JOURNAL UPLOAD IS ADDING ZEROS TO SEGMENT VALUES

    제품 : FIN_GL
    작성날짜 : 2003-09-16
    (ADI) JOURNAL UPLOAD IS ADDING ZEROS TO SEGMENT VALUES
    ======================================================
    Problem Description
    ADI에서 Journal Import를 시도할때, Account segment value값에"0"를 자리수만큼 채워서 upload를 시도하는 경우가 있다.
    예를들어, segment value가 300 인데, ADI에서 Journal Import시
    0300 으로 바뀌는 경우이다.
    이 경우, Segment Value중에 0300이라는 값이 없기 때문에, upload시
    에러가 발생한다.
    재현방법 :
    Responsibility = General Ledger Super User
    ADI path = Click on the Ledger Book from the ADI toolbar/Enter Journals
    1. Log on to ADI as the General Ledger Super User.
    2. Proceed to the Create Journal Worksheet form using the above navigation.
    3. Choose the appropriate journal type and click on the green check mark to
    continue. This will load Excel and the appropriate journal template.
    4. Enter your Journal information in the header and body. Place the value of
    the segments that you would like in the segment value portion of the journal.
    5. Once the journal is completed, click on the Ledger Book from the ADI toolbar
    and select the green arrow to upload the journal.
    6. Once the journal upload is complete, you notice that the values that were
    uploaded for a certain segment have a zero added to them.
    Solution Description
    "0"가 자릿수만큼 채워지는 것을 막기위해, ADI setup중 "Zero Pad" 기능을 uncheck한다.
    Responsibility = General Ledger Super User
    ADI path = Click on the Hammer and Screwdriver(망치와 드라이버가 그려져 있는 Icon) from the ADI toolbar/General
    options/Settings
    1. Log on to ADI as the General Ledger Super User.
    2. Proceed to the Settings form using the above menu path.
    3. Uncheck the Zero Pad check box on this form.
    4. Save your changes and repeat the journal import process for this journal.
    Explanation
    "Zero Pad"기능은 check되었을때, 해당 Segment의 Maximun Size만큼 "0"으로 채워준다.
    이 기능을 uncheck하면, "0"의 추가확장 없이 입력된 그대로를 사용하게 된다.
    Reference Documents
    Note : 113051.1

    Hi,
    Are you choosing Functional Journals template and trying to upload Foreign Currency journals or vice versa? Please check
    Regards,
    Sridhar

  • Want to hide/eliminate the leading Zeros in the Variable popup for0MATERIAL

    I have a requirement where 0MATERIAL is having leading zeros and it has the MATN1 conversion routine in the production system.I want to only remove the leading zeros in the Variable popup in report for 0 MATERIAL witohut changing the definition of the object as it has too much production data to change.
    Best Regards
    Tagore

    Hi,
    You will have to write some code in F4 help BADI, please refer the sap note 1416952. And you can take help of following function module to remove leading zeros,
    CONVERSION_EXIT_ALPHA_OUTPUT.
    If above thing doesn't help then you will have to create virtual key figure.
    Regards,
    Durgesh.

  • Labview is reading zero from shared variable

    Hello everyone 
    -I have a problem in labview shared variable cause it reads only zero value for all inputs and outputs and timers in S-1200 ...etc
    but in NI OPC server using quick client it reads the correct value but when adding them in labview project they are not reading the correct value and only retruing zero
    any suggestions 
    Thanks

    Hi,
    I recently finished the commisioning of the system I started to work upon. Hence the delay to come back to this thread.
    During the commissioning of the system, I was concentrating on finalizing the system functionality and was using only the PC#1. Now when all the system functions were finalized, we duplicated the changes to PC#2 and started the operation.
    What we observed when the PC#2 was started, was that if we were to open the same HMI page as in PC#1, the operation of the HMI was very sluggish. When we selected a different page for both PC#1 and PC#2, the HMI operation was good,  all operations seemed to happen in real time!!
    To give a background of the HMI, we have a subpanel to which the desired HMI page/screen is loaded. This loads a VI related to the HMI page.
    Here, I am guessing that when I load the same page in both the PCs, the read/write operations to the shared variable(it is the same in both PC, and is deployed in a library on the cRIO) are some how hindered due both PCs trying to access the same network resource from different locations.
    Is this guess correct? Any work arounds or solutions? Do I need to post any more information?
    Thanks in advance,
    Regards

  • Adding zeros to the external material number

    Hello Friends,
    I needed your assistance with  a routine in BI 7, Infosource Transformations or in the Infoobject transformations (update Rules).
    I have data comming from a  flat file without the leading zeros for an infoobject.I need to have the leading zeros but i need a code that will do a record count and then accordingly add the zeros.
    EX:     1)  67909344 i need it to look  like  000067909344
              2) 505289 then i need it to look like 000000505289
    Basically, if its 8 digit number then i want 4 zeros before it and if its a 6 digit number then i need 6 zeros before it, those are the only tyoes ill have 6 and 8 digits
    Thanks alot.

    Hello Ronit,
    You can use FM CONVERSION_EXIT_ALPHA_INPUT.
    Declare a variable to contain that value, for example, 67909344.
    If you declare a variable like CHAR10, and use it like this:
    lv_variable = '67909344'.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING                                  
      INPUT  = lv_variable                        
    IMPORTING                                  
      OUTPUT = lv_variable.                       
    The result will be 0067909344.
    If you declare the variable as length 12, the result will be 000067909344.
    And it goes on...
    See if this can be helpful to you.
    Kind regards,
    Bruno
    Edited by: Bruno Garcia on May 27, 2008 5:54 PM

  • Adding zeros to a character string

    Hello friends,
    I want to add leading zeros for a field.
    the field is a character string.
    for example ,
    data: A(5) type c.
    now when A  = 'ab' (non-numeric value)
    i want this to be converted in '000ab'
    so, is there any standard Function module or any other way for doing this conversion ?
    I tried the FM   'CONVERSION_EXIT_ALPHA_INPUT' but this FM does not work for non-numeric inputs..
    Thanks.

    Hi,
    The packed field is transported right-justified to the character field, if required with a
    decimal point. The first position is reserved for the sign. Leading zeros appear as
    blanks. If the target field is too short, the sign is omitted for positive numbers. If this is still not sufficient, the field is truncated on the left. ABAP indicates the truncation with an asterisk (*). If you want the leading zeros to appear in the character field, use UNPACK instead of MOVE.
    UNPACK
    Converts variables from type P to type C.
    Syntax
    UNPACK <f> TO <g>.
    Unpacks the packed field <f> and places it in the string <g> with leading zeros. The opposite of PACK.
    Regards,
    Bhaskar

  • Adding zeros to filenames when exporting in Lightroom "Filename-001" "Fliename-002" etc?

    Hi, does anyone know if it is possible to add zeros before numbers when exporting files eg: "Filename-001" "Fliename-002" etc? The default setting is "Filename-1" "Filename-2" ect. The reason I want to have zeros in the number sequence is that certain software will display files in the wrong numerical sequence eg: "Filename-1" "Filename-10" Filename-11" etc and then "Filename-2" after "Filename-19". If zeros are added the files will always be displayed in the correct sequence "Filename-001" "Filename-002"... "Filename-009" "Filename-010" "Filename-011" etc.

    Just customize the filename using the template editor, and use the Sequence token set to the number of leading zeroes you want, as shown.

  • Adding Formulas to Substitution Variables

    Hi All,
    I am using EPM system 11. I have a classic planning application . On my dataform , I have Year in the Point Of View and Period on Column.
    I need to show Current Year,Next Year and Current Month (derived from system date) on the form.
    For achieving this I created three substitution variable in EAS *&CurYear,&NextYear,&CurMonth.*
    Say e.g if the System date is *10th October 2009* then CurYear would show FY09 , NextYear would show FY10 and CurMonth would show Oct.
    For the time being , I hardcoded these values..but I am trying to get through a way of deriving the above values from system date
    Can somebody please advice how i can proceed to get the variables to work ....
    Kind Regards.
    Mirka

    Hi,
    How about something like
    SET year=FY%DATE:~8,2%
    SET month=%DATE:~3,2%
    *:: Remove leading zero if it exists...*
    set /a month=1%month% - 100
    set monthstring=Jan@Feb@Mar@Apr@May@Jun@Jul@Aug@Sep@Oct@Nov@Dec
    for /f "tokens=%month% delims=@" %%j in ('echo.%monthstring%') do (
    set month=%%j
    echo %month%
    echo %year%
    Say the year is 2009, this would set year=FY09
    And month should be converted to a month name
    ok?
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Validations with date(Adding zero's)

    Hi,
      can anyone tell me regarding this:
    if the date is 5/5/2008 - the output should be 05/05/2008, means 0 should be concatenated in month and date.
    else if date is 5/12/2008 - the output should be 05/12/2008
    means 0 should be concatenated only in front of 5.
    please help.

    Hi,
    I cant get your requirement clearly. Anyway I give you some solution below:
    1. Declare the variable of TYPE SY-DATUM, so that automatically concatenate zero in front.
    OR
    2. You need to declare one variable as STRING and assign the input date to the string and split it at '/' then store date and month in two other variables and check those two variables are less than 10. If so then concatenate '0' in front else leave as it and finally concatenate as per your requirement.
    Regards,
    Raghu

  • Adding zeros addition

    Hi All,
    there is a variable with length 2,
    if variable having single charcter value like '1'  need to make the variable value '02'
    how to check the variable length and add the zero if variable having only one character.
    please help me
    regards
    krishna

    Hi,
    try the following code..
    data : var type i,
    var2(3) type n.
    var = 2.
    if var < 10.
    var2 = var.
    endif.
    write /: var, var2.
    var2 will ouput with leading zeros...
    Regards,
    Viji

  • Adding Multiple Task Sequence Variables to Devices using C#

    Hello,
    I am hoping someone can help me with a small program I am writing for our company.  We are writing a small program in C# to import computers to a particular imaging collection and we need 2 variables set.  We have been able to create a single variable
    using this guide: http://msdn.microsoft.com/en-us/library/jj218235.aspx
    The problem is that when we write the 2nd variable, the first one is overwritten.  It looks like that property is an array.  I've been trying to find a way, either using the SCCM 2012 R2 SDK or just adding it via the standard System.Management
    functionality.
    I'm sure there is a way to do it, the Powershell CMDLets will add variables rather than overwrite.  We are trying to avoid that due to some PowerShell restrictions.
    Any help would be much appreciate, I'm sure the answer is not as difficult as I'm making it but I'm stuck as I am not really a programmer, but, like many of us, have to function as one at times.
    Thanks!

    Certainly, here you are (I've removed some company-specific info and replaced it with generic info). I'll note - this code does work to add a variable to a device in SCCM. When adding multiple variables though, the first one is replaced. This code only seems
    to work for adding 1 variable which is what is causing me the headache.
    privatevoidAddVariable()
    SmsNamedValuesDictionarynamedValues
    =newSmsNamedValuesDictionary();
    WqlConnectionManagerconnection
    =newWqlConnectionManager(namedValues);
    connection.Connect("SCCMSITESERVER");
    try
    // Get the computer settings.
    // strResourceID is obtained via separate method “GETRESOURCEID()”
    IResultObjectcomputerSettings
    =null;
    IResultObjectcomputerSettingsQuery
    = connection.QueryProcessor.ExecuteQuery(
    "Select * from SMS_MachineSettings where ResourceId = '"+strResourceID
    +"'");
    foreach(IResultObjectsettings
    incomputerSettingsQuery)
    computerSettings = settings;
    if(computerSettings
    == null) // It doesn't exist, so create it.
    computerSettings = connection.CreateInstance(@"SMS_MachineSettings");
    computerSettings["ResourceID"].StringValue
    = strResourceID;
    computerSettings["SourceSite"].StringValue
    = "SITECODE";
          computerSettings["LocaleID"].IntegerValue
    = 1033;
    computerSettings.Put();
    computerSettings.Get();
    // Create the computer variable.
    List<IResultObject>computerVariables
    = computerSettings.GetArrayItems("MachineVariables");
    IResultObjectcomputerVariable
    =  connection.CreateEmbeddedObjectInstance("SMS_MachineVariable");
    computerVariable["Name"].StringValue
    = strVariableName;
    computerVariable["Value"].StringValue
    = strVariableValue;
    computerVariable["IsMasked"].BooleanValue
    = false;
    // Add the computer variable to the computer settings.
            computerVariables.Add(computerVariable);
    computerSettings.SetArrayItems("MachineVariables",
    computerVariables);
    computerSettings.Put();
    catch(SmsExceptione)
    MessageBox.Show("Failed
    to create computer variable: "+ e.Message);
    connection.Close();
    Thank you for your help

  • Adding messages to the Variable entry screen in web report

    I need to add a message or note to the variable selection screen on a web report. I need this message or note to be displayed somewhere on the same screen with the variable list. I found something similar in BW Expert regarding pop-up messages, but this does not work with web templates. Does anyone know of a way to add a static (or dynamic) message to this initial screen of a web report?

    In my clients place, they are ready to do the SAP Mod based on "CL_RSR_WWW_VARIABLE_SCREEN" to have a Alert Message which sort of based on different idea.
    Does anyboay have an idea on where to make the change?
    Thanx
    Arun

  • Adding Spaces in the variable.

    Hi All,
    the problem scenario is :
    I have a varaible of type c and length 10, and its filled with only 6 characters. Further there is another Variable of type c and size 4 , both need to concatenated .
    The problem is when I concatenate both variables they come up joined. I need to have the 4 characters space between both variables.

    Hello,
    CONCATENATE is not going to be of any help.
    Try like this:
    DATA:
    V_STR1 TYPE CHAR10 VALUE '123456',
    V_STR2 TYPE CHAR4 VALUE '1234',
    V_STR TYPE STRING.
    MOVE V_STR1 TO V_STR.
    V_STR+10 = V_STR2.
    WRITE: V_STR.
    Hope this helps.
    BR,
    Suhas

  • Adding commas in quan variable of smartforms

    hi experts,
    In my smartforms,i have a variable temp_menge which is having value 1000000 but i want to get it displayed as 1,000,000.How to write the same.?????
    Thanks,
    Gaurav
    Edited by: Gaurav Kumar on Feb 26, 2008 2:30 PM

    Hi,
    There might be 2 possibilities. One is data type. Symbols of the DEC, CURR, INT, and QUAN data types are normally formatted with the a ‘thousands’ separator character. The T option allows you to omit this separator character.
    Syntax:
    &symbol(T)&
    The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal places and an output length of 17.
    &EKPO-MENGE& -> 1,234.560
    &EKPO-MENGE(T)& -> 1234.560
    So one thing is change your data type to TYPE P or remove the (T) from your code. This should work.
    Reward points if helps.
    Regards,
    JLN

  • Adding Zeros infront of a field in Message Mapping

    Hi,
    I need to add zeros infront of my target field (eg Target Field length is fixed (10). If incoming field is having only 3 digits (123), I need to add 7 (10-3) zeros infront of my target field (0000000123). How to go about it. Is there any standard functions to do this ?
    Thanks in advance,
    Jose Augastine

    Try using this UDF
    double d = Double.parseDouble(a);
    DecimalFormat df=new DecimalFormat("0000000000");
                   StringBuffer sb=new StringBuffer();
                    df.format(d,sb,new
    FieldPosition(NumberFormat.INTEGER_FIELD));
                   return(sb.toString());
    Regards,
    Jai Shankar.
    Message was edited by: Jai Shankar

Maybe you are looking for