jdhc3m
13th April 2011, 20:33
Does anyone know a function to transform a variable into a number with 4 decimals places?

example:

var = 0,00026 * 6
var = 0,0016 :)

I tried to definition the domain with 4 decimals places, but in this case, appears with 5 decimals places. :(

bdittmar
13th April 2011, 21:36
Does anyone know a function to transform a variable into a number with 4 decimals places?

example:

var = 0,00026 * 6
var = 0,0016 :)

I tried to definition the domain with 4 decimals places, but in this case, appears with 5 decimals places. :(

Hello,

round()
Syntax:

function double round (double value, long diga, long mode)

Description


This rounds a given value to a specified number of decimal places.


Arguments

double value The value to be rounded.

long diga The number of decimal places to which value is to be rounded.

long mode 0 truncate (for example, both 1.5 and 1.49 are rounded down to 1)

1 normal round (for example, 1.5 is rounded up to 2; 1.49 is rounded

down to 1)

2 round up (for example, both 1.5 and 1.49 are rounded up to 2)


Return values

The rounded value. Or the original value ( value ) if an error occurs.

Because the return value is of type double, the number of digits after the decimal sign is always 6. For example, round(1.345, 2, 1) returns 1.350000.

But digits are always 6 !

Regards

jdhc3m
13th April 2011, 21:56
I need to return a number with 4 decimal places

rahul.kolhe22
14th April 2011, 08:41
Hello,

If I am not worng, you just want to display the field with 4 decimal either on session or report.

In that case you can specify the 'Display Format' in session editor and 'Print Format' in report for that particular field.

Or else if you just want the value for that field in the program script uptill 4 decimal points then can use edit$ function.

Hope it helps you.

Regards,
--Rahul

jdhc3m
14th April 2011, 17:36
Right, do you have a ready exemplo using the edit$?

bdittmar
14th April 2011, 20:59
Right, do you have a ready exemplo using the edit$?

Hello,
0,00026 * 6 gives 0,001560, so you're rounding for var = 0,0016

in you case the function is: edit$(var, "9DV9999")

----------------------------
edit$()
Syntax:

function string edit$ (void expression, string format)

Description


This formats an expression according to a specified format.


Arguments

void expression The expression that must be formatted. This can be a floating point expression, an integer expression, or a string expression that returns an integer or a floating point value.

string format A string that defines the required format. The following formatting characters are available:

9 Use to reserve a position for a digit. Inserts a 0 if there is no significant digit in that position.
Z Use to reserve a position for a digit. Inserts a space if there is no significant digit in that position. You can use this both before and after the decimal sign.
V Use to indicate the position of the decimal sign. No decimal sign is displayed. To display a decimal sign, you must enter ‘D’, a period [.], or a comma [,] immediately after this character, depending on which decimal sign you wish to use.
D Use to display the decimal sign as defined in the data dictionary.
T Displays a thousand sign. The representation of the thousand sign is defined in the data dictionary.
- If this is the first or last character in a format string, a negative value is prefixed or suffixed by a minus sign [-] and a positive value is prefixed or suffixed by a space. Minus signs in other positions have the same meaning as ‘Z’.
+ If this is the first or last character in a format string, a negative value is prefixed or suffixed by a minus sign [-] and a positive value is prefixed or suffixed by a plus sign [+]. Plus signs in other positions have the same meaning as ‘Z’.
* If this is the first character in a format string, all spaces to the left of the most significant digit are filled with asterisks .

All characters other than those described above are copied directly to the output string. Periods [.] and commas [,] are exceptions. These are reserved for use as decimal signs and thousand signs.

If the format expression is enclosed by parentheses, these are displayed only if the result is negative.


Return values

The function returns the formatted expression. If the specified expression does not fit in the format string, the result is filled with the overflow characters defined in the data dictionary.

Regards