# How to define a constant (but variable)?

Hello AmiBroker Support Team How to define a constant (but variable)?
I mean such a situation:
I define as a constant the symbol "xz",
in the following way:
if the current share price is 110.20, then xz = 110.00
if the current share price is 110.50, xz = 111.00
if the current share price is 110.60, then xz = 111.00
(similarly, at the price: 0.87 to, xz = 0.90 and if 39.45 it, 39.50 according to stock exchange requirements)
So how do you define a constant that changes, rounds to the nearest, full current price?

greetings Is it really so difficult using forum search?

``````function RoundToDecPlaces( value, decplaces ) {
/// at Amibroker forum:
powten = 10^decplaces;
result = round(value * powten) / powten;
return result;
}

value = MxFromString( "[110.2;110.5;110.6]" );

for( i = 0; i < MxGetSize(value,0); i++ )
{
printf( "Raw value: %1.2f\n", value[i] );
printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value[i], 0 ) );
}

value = 0.87;
printf( "Raw value: %g\n", value );
printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value, 1 ) );

value = 39.45;
printf( "Raw value: %g\n", value );
printf( "rounded: %1.2f\n\n", RoundToDecPlaces( value, 1 ) );
``````
5 Likes