Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using a floating point number

former_member195355
Participant
0 Likes
1,872

Hiya,

I have the following table field:

I'd like to use the contents of it to do some calculations but the value always appears slightly odd.

I mean if I read and write the value to screen I get the following:

When I would have expected it to show 12.33

Can anyone help me understand what I might be doing wrong please?

Many thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,826

Hello.

Check this post, i guess that it will help you to solve ur problem.

Regards

Miguel

8 REPLIES 8
Read only

Former Member
0 Likes
1,827

Hello.

Check this post, i guess that it will help you to solve ur problem.

Regards

Miguel

Read only

0 Likes
1,826

Thanks Miguel1

That was helpful but I'd like to do some calculations with the floating point number and I don't think Char fields are recommended for calculations..

Or do you think I should do this:

-Get the floating point number from the table.

-CALL FUNCTION 'CEVA_CONVERT_FLOAT_TO_CHAR' to convert the number into a character.

-Move the number from the character field into a NUMC field(?) and then do my calculations with that value?

What do you reckon?

Read only

0 Likes
1,826

Hi.

it is easier to move a char to a numc to do calculations. So half way it is done using that FM.

Regards

Miguel

Read only

0 Likes
1,826

Thansk Miguel.

I think the problem with that function module is that it expects you to know how many decimal places you would expect - via the FORMAT_IMP parameter.

For me that number could be variable....

Don't really know what to do now.

Read only

0 Likes
1,826

Hi,

Yes, as u said, u need to show just 2 decimals...12.33

so all the numbers will be showed with 2 decimals...

check the FM in development system and so dome calculation, maybe it will work.


Regards

Miguel

Read only

0 Likes
1,826

Why don't you want to use the FLOAT for calculations? If you fear rounding errors just move the value to a DEC field.

Read only

0 Likes
1,826

Hi Uwe,

Sorry I'm new to floating point numbers and I'm finding them a little scary. I'm probably asking lots of stupid questions but what you write makes sense.

-Do the calculation with the floating point number.

I'm doing a total for a currency field field with 2 decimal points:

Once I've done my calculation would it be okay (i.e. good practice) to simply move my value into this field?

Or even to use this field directly in the calculation i.e.

LV_TOTAL_COST = LV_TOTAL_COST * Floating_point_value

Sorry if my questions sound stupid but I want to follow vbest practice when coding.

Many thanks!

Read only

0 Likes
1,826

Hi Robert,

there are no stupid questions (mostly), just stupid answers.

Floats are not scary, just the scientific representations of values. You probably know the meaning of 1.234 * 105

And yes, you can use LV_TOTAL_COST = LV_TOTAL_COST * Floating_point_value.