function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HarmpieHarmpie 

How to prevent Double to be displayed as 6.0E+7

I have created a VF page, which is included in the page layout of an object, that displays amounts from related records. Amount above 10.000.000 are displayed in the 6.0E+7 notation on screen. How can I prevent this?

 

The code that sets the field value:

this.noc1 = afcst.Forecasted_Amount__c;

 

Where Forecasted_Amount__c is a normal currency field in SF. noc1 is a Double in the code, however I tried with Decimal as well.

 

The pagecode that displays this field:

<td><apex:outputText id="noc1" value="{!noc1}" /></td>

 

 

Another question I have, is how to prevent the numbers to show with 1 decimal position. 1.000.000 will always be displayed as 1000000.0, regardless of what method I append to the first line of code (round(), toPlainString() etc..)

VisualForceVisualForce

Hi..

 

   use apex:outputfield instead of outputtext

 

If its doesnt work

  

 

   Use decimal data type for rounding ur number

 

decimal noc1=0; public decimal getnoc1() { noc1=afcst.Forecasted_Amount__c; return (noc1.divide(1,2,System.RoundingMode.UP)); }

 

Its round two decimal point

 

 

HarmpieHarmpie
Hi VisualForce. Thanks for the reply. It did not work. First I tried the outputField, but that will not work, because noc1 is not an SObject field. Recoding all the Doubles (there's more variants to noc1...noc1-6 and capex1-6) to Decimals made Salesforce give me Internal Server errors. Somehow decimals cannot be stored in currency fields ???
andresperezandresperez

Hi,

 

Try noc1.LongValue();

HarmpieHarmpie

The fix I applied is rather ugly, but it works.

 

In order to get and set Decimals or Doubles from controller to VF page and vice versa, you need to juggle the type. In other words: when used in the VF page, transform the figure to a String, when writing back to the controller, convert it back to Decimal or Double, applying all the string replaces needed to filter out comma's, dots etc.

 

I hope that <apex:inputfield>'s will be able to display (and save) large Decimals and Doubles correctly one day.... for now, juggle it :)