Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

decimal...

Status
Not open for further replies.

TKS

New Member
Hello,

i'm building
a project which need to be able to
calculate values very accurate...

is there a way to be able to produce a value on a display like 20,5

or 1005,5 of something..

my pic rounds every value up.

TKS
 
TKS said:
Hello,

i'm building
a project which need to be able to
calculate values very accurate...

is there a way to be able to produce a value on a display like 20,5

or 1005,5 of something..

my pic rounds every value up.

You don't mention what language you are using, if it's an integer BASIC that would explain why.

The trick is to scale the values, so 10.1 becomes 101 and 20.5 becomes 205 - if you multiply them together you get 20505, you then simply display the number with the decimal point inserted in the correct place, in this case 205.05 is the correct result. As you've multiplied (scaled) both inputs by 10, you have to divide the output by 100 - except you don't actually divide, you simply stick the decimal point 2 digits in.

This gives perfect accuracy, with no truncation of results - obviously your maths routines need to be of sufficient resolution to deal with the numbers involved.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top