Skip to main content
Oct 22, 2013 5:38 AM UTC
Question

Double 2 String Relation

Hi everyone,

some of us, me including, often need a good and robust way to convert a double to string. The internal functions of Creo and ProE can't manage that.

Many solutions start with converting the double number by number. In this case you have alot of IF-relations which makes the relation very big.

Here is my new relation. I don't see that anywhere so i want to share this with the community.

Just insert your double-number in the DBL = and edit the format for your request.

--------------

DBL = 100.000000     /* Your Double (could be d5 or similar)

FORMAT = "0,00" /* Format 0,000

/* start formating

STRING = ITOS(FLOOR(DBL))

IF string_length(STRING) == 0

  STRING = "0"

ENDIF

DBL_DECIMAL =(DBL - FLOOR(DBL))*10^(string_length(FORMAT)-2)

STRING = STRING + Extract(FORMAT, 2, (string_length(FORMAT)-1)-string_length(itos(DBL_DECIMAL))) + ITOS((DBL - FLOOR(DBL))*10^(string_length(FORMAT)-2))

/* end formating

Result = STRING

---------------

~

Nico

    1 reply

    Nico1Author
    Nov 21, 2013 6:12 AM UTC

    In addtion my mass to string-relation:

    MASS = PRO_MP_MASS*1000

    WEIGHT = itos(floor(MASS))
    if string_length(WEIGHT) == 0
        WEIGHT = "0"
    endif
    WEIGHT= WEIGHT+ extract("0,000", 2, 4 - string_length(itos((MASS - floor(MASS))*10^3))) + itos((MASS - FLOOR(MASS))*10^3)