PDA

View Full Version : decimal


Rikard
08-11-2005, 03:46 AM
Hi
Im trying to make some calculations within a program.
What i understand i cant make an input in decimals like 1.2345 in an input box an convert it to a number like this:

inputp1tom = Input.GetText("p1tom");
inputp1tom = String.ToNumber(inputp1tom);

so what do i need to do to make it take a 4 decimal number and make a calculation against another number and give a 4 decimal answer.

This is my code:

inputp1tom = Input.GetText("p1tom");
inputp1tom = String.ToNumber(inputp1tom);

inputp1vat = Input.GetText("p1vat");
inputp1vat = String.ToNumber(inputp1vat);

gramfargp1 = inputp1vat - inputp1tom
Label.SetText("p1farg", gramfargp1);

Corey
08-11-2005, 03:48 AM
Hi. Sounds like Math.Round is the ticket. Here's a working example, hope that helps. :)

http://www.indigorose.com/webhelp/ams50/Program_Reference/Actions/Math.Round_Examples.htm

Rikard
08-11-2005, 03:59 AM
that is probebly right but i cant get it to work
the 2 numbers that will be in the calculation is 4 decimals and when i do a calculation with decimals ill get the result 0

take a look at this code should that work?

inputp1tom = Input.GetText("p1tom");
inputp1tom = String.ToNumber(inputp1tom);

inputp1vat = Input.GetText("p1vat");
inputp1vat = String.ToNumber(inputp1vat);

gramfargp1 = Math.Round(inputp1vat - inputp1tom, 4);

Label.SetText("p1farg", gramfargp1);

Corey
08-11-2005, 04:32 AM
Hi. You mean padding non-decimal numbers? Here's a working example attached. I set it up to only subtract since that's the example you posted. So in this file it will subtract number 2 from number 1 and pad/round the answer to 4 decimal places each time. All the actions are on the button, in the OnClick event. Hope that helps. :)

Rikard
08-11-2005, 04:53 AM
Thanx for youre help Corey.
Now i se what the problem is
im from sweden and in sweden we use , as a devider (is devider the right name) and in the english language you use . is it posible to thell the app that , is the same as.

Corey
08-11-2005, 04:55 AM
Yes, what does a "divider" look like? Please show me the character and I will adjust the script. :)

Rikard
08-11-2005, 04:59 AM
What i ment was:
in sweden it looks like this 0,1234 and in english it looks like this 0.1234 the diferens is ., my app dosent work with , instead of .
when someone in sweden enters a number in p1tom and p1vat they will add it like this 0,1234 not 0.1234


inputp1tom = Input.GetText("p1tom");
inputp1tom = String.ToNumber(inputp1tom);

inputp1vat = Input.GetText("p1vat");
inputp1vat = String.ToNumber(inputp1vat);

gramfargp1 = Math.Round(inputp1vat - inputp1tom, 4);

Label.SetText("p1farg", gramfargp1);

Corey
08-11-2005, 05:05 AM
Hi. OK this attached example will handles inputs with commas as well as decimals and then delivers the answer with a comma instead of a decimal. Hope that helps. :)

Rikard
08-11-2005, 06:05 AM
thank you now it works

Corey
08-11-2005, 06:06 AM
Glad to hear it's working. :)

csd214
08-15-2005, 06:08 AM
Hello neighbour,

Those of us living outside “the dot area” (US/CAN/UK...) have some additional challenges. The decimal symbol (dot or comma) is one of them, but we have more; the digit grouping symbol (comma, dot, space or single quote) and the list separator (comma or semicolon). All of these values can be found in the user’s Registry.

I recommend Lorne’s great examples Function: Get the Valid Numeric Characters for the Current Locale (http://www.indigorose.com/forums/showthread.php?t=7785) and Function: Validate the Contents of an Input Object (http://www.indigorose.com/forums/showthread.php?t=7780)

And don’t forget the letters outside the A-Z range. In Sweden Ä.Ö, Å ä, ö, å. Put the Swedish letters randomly into a table; execute Table.Sort(). The result is not what you expected. You should read Brett’s post Tip: Changing the Locale (http://www.indigorose.com/forums/showthread.php?t=7886)


Yes Corey, it’s “Comma, comma, comma, chameleon” once again.

Rikard
08-16-2005, 10:51 AM
Thank you csd214 I really appreciate all this kind of information.

csd214
08-16-2005, 11:14 AM
You are welcome. We have similar problems; NO; I mean similar challenges. There are no problems; only solutions. :p

Intrigued
08-16-2005, 12:02 PM
You are welcome. We have similar problems; NO; I mean similar challenges. There are no problems; only solutions. :p

I once was told to say "setbacks" and not problems.

:D