Data360 Analyze

Welcome to the Data360 Analyze community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Here are some useful links where you can find more information:

Product Announcements  Product Documentation  Ideas Portal

Discussions

Members

Resources

Events

 View Only
  • 1.  Write the String (double value) as numeric value(2 deciaml point) in the Excel sheet

    Employee
    Posted 10-22-2020 14:41

    Hi,

    I have a input data with the below values as string, I want to write the data into excel file as numeric with 2 decimal point.

    Input Data(String) -> Excel file value (Numeric with 2 decimal point)

     

    Also I need to know the conversion of string to double.

     



  • 2.  RE: Write the String (double value) as numeric value(2 deciaml point) in the Excel sheet

    Employee
    Posted 10-23-2020 06:31

    Input Data (String)  -> Excel File (Numeric)

    12.03 -> 12.03

    01.03-> 01.03

    23.45->23.45

     

    The reason that I'm looking to write the date into Excel as Numeric to apply the excel formula once the output file created by the Dataverse.

     



  • 3.  RE: Write the String (double value) as numeric value(2 deciaml point) in the Excel sheet

    Employee
    Posted 10-23-2020 08:20

    Not all floating point numbers can be expressed exactly so you cannot always guarantee to have two decimal places for a all numbers. You can round numbers to two decimal places and that will be approximately the value you want. You can output the number of cents as an integer value and then (within Excel) divide this by 100 as part of your formula.

    Below are some options for generating string, float (double) and integer representations of floating point numbers using the Transform node. The input data is in the 'Data' field.

     

    Which produces the following results when viewed in the Analyze Data Viewer:

    When the data is output to Excel, the corrsponding data is shows as:

    Note that the 'Data' field and the 'Decimal_String' columns are formatted in Excel as strings containing numeric values.

    Also note that in the process of formatting a float value to a string with a specified number of decimal places, the number has been rounded implicitly (see rows 8 and 9 above).

    The code used in the Transform node scripts are:

    #### ConfigureFields

    #Configure all fields from input 'in1' to be mapped
    #to the corresponding fields on the output 'out1'
    out1 += in1

    out1.Numeric_value = float

    out1.Rounded_value = float

    out1.Decimal_String = unicode

    out1.Cents_Value = int

     

    #### ProcessRecords

    #Copy all fields from input 'in1' to the corresponding output fields
    #in output 'out1'. Copies the values of the fields that have been setup
    #in the mapping defined in the ConfigureFields property
    out1 += in1

    if in1.Data is Null:
    ## Defaults for missing data
    out1.Numeric_value = Null
    out1.Rounded_value = Null
    out1.Decimal_String = ""
    out1.Cents_Value = Null
    else:
    NumVal = float(in1.Data)
    out1.Numeric_value = NumVal
    out1.Rounded_value = round(NumVal, 2)
    ## Format the value as a string with 2 DP
    out1.Decimal_String = "{0:.2f}".format(NumVal)
    ##Output the number of cents as an integer
    out1.Cents_Value = int("{0:.0f}".format(100 * NumVal))