0

I have a SSJS function with the below lines of code that keeps returning the value of the field 'day' in scientific notation. I have tried using BigDecimal in addition to the below with no difference. All the other questions on SO and other blogs about scientific notation to decimal have examples for java so I have taken my best attempt at how those examples should be interpreted for SSJS.

Value stored in document accessed with exportDoc in code below using field name
Field Name: day
Data Type: Number
Data Length: 8 bytes
Seq Num: 1
Dup Item ID: 0
Field Flags: SUMMARY

-37.5

    exportDoc.getItemValueDouble('day');
    returned value: -3.75E1

    var dform:java.text.DecimalFormat = new java.text.DecimalFormat("0.##");
    var hrs:String = dform.format(exportDoc.getItemValueDouble('day'));
    //using hrs:Double returns same value
    returned value: -3.75E1

    var hrs:String = dform.parse(@Text(exportDoc.getItemValueDouble('day')));
    //using hrs:Double returns same value
    returned value: -3.75E1

    var hrs = Number(exportDoc.getItemValueDouble('day'));
    returned value: -3.75E1

If I multiply the exportDoc.getItemValueDouble('day') by 10 I get -375, if I then divide by 10 I still get the -3.75E1, and if I use exportDoc.getItemValueInteger('day') I get -38.

This doesn't occur with whole negative numbers like -2, -108, etc. or positive numbers even if not a whole number.

Any help is greatly appreciated as this is causing issues when importing into our HRIS system.

Dwain Wuerfel
  • 373
  • 1
  • 11
  • That is really weird. I bet that if you multiply by 10, then convert to a string, then convert back to a number, then divide by 10, you will get -37.5. I have no idea why it is insisting on converting to scientific notation. – Steve Zavocki Apr 11 '13 at 19:57
  • Also if that doesn't work, try tagging the question as 'javascript', and you will reach a wider audience. – Steve Zavocki Apr 11 '13 at 19:59
  • I multiplied by 10, then converted to a string, then converted back to a number, then divided by 10 and still got the scientific notation. Guess I will have to report a bug to IBM!!! – Dwain Wuerfel Apr 12 '13 at 04:45

1 Answers1

1

Are you sure you haven't set some kind of converter?

I just pulled together a test page but it's not happening here:

<xp:panel id="upperPanel">
    <xp:label value="Number field (shows value stored in number field): "
        id="label1"></xp:label>
    <xp:inputText id="inputText1" value="#{document1.subNum}">
        <xp:this.converter>
            <xp:convertNumber type="number"></xp:convertNumber>
        </xp:this.converter>
    </xp:inputText>
</xp:panel>
<xp:panel id="lowerPanel">
    <xp:label id="label2"
        value="Calculated Number (computes value using .getItemValueDouble()): ">
    </xp:label>
    <xp:text escape="true" id="computedField1">
        <xp:this.value><![CDATA[#{javascript:currentDocument.getItemValueDouble("subNum")}]]>
        </xp:this.value>
        <xp:this.converter>
            <xp:convertNumber type="number"></xp:convertNumber>
        </xp:this.converter>
    </xp:text>
</xp:panel>

Looks like this then:

screenshot

I even tried setting the Notes form's field property to "scientific", but (of course) that doesn't have any influence on the Xpages.

Probably I'm not getting what you're trying to do?

Lothar Mueller
  • 2,528
  • 1
  • 16
  • 29
  • Yeah, I am actually trying to export the field value and get the scientific notation when using the .getItemValueDouble on a field with a negative value that isn't a whole number. I will post the code prior to the .getItemValueDouble call this weekend. – Dwain Wuerfel Apr 13 '13 at 02:19