Formating numbers

If you have a question about the software please ask it here.

Re: Formating numbers

Postby dezsoe » Mon Jun 25, 2018 4:08 pm

It's written in the C# core (if I understand what you ask):

Code: Select all
double test1 = 12.123456789
double test2 = test1.ToString("F4");
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Formating numbers

Postby dezsoe » Mon Jun 25, 2018 5:52 pm

Yes, of course, sorry. The second line sould be a string instead of double. I thought that you want to display the formatted number.

Code: Select all
double test1 = 12.123456789
string test2 = test1.ToString("F4");
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Formating numbers

Postby Dan911 » Mon Jun 25, 2018 7:18 pm

If you want to keep it a double use Math.Round()

double test1 = 12.123456789;
double test2 = Math.Round(test1,4);
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Formating numbers

Postby dezsoe » Mon Jun 25, 2018 8:22 pm

1.1 will have only one decimal. If you format the string with e.g. "F4", then you can write to the DRO with AS3.Setfieldtext(yourdouble.ToString("F4"), 20000); and it will have 4 decimals. I thought that this is the job. :)
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Formating numbers

Postby Dan911 » Mon Jun 25, 2018 11:20 pm

Vmax549 wrote:Dan , THAT was a simple solution ;) and it writes ok to a dro.

Dezsoe, question?? I was told long ago to write to a DRO that you used a double value only.

You wrote to it using a String Value. Is there any drawbacks to using a string value ?? Teh manual sorta warns against it.

I thought SetfieldText() was only to write to a field containing text ??

(;-) TP


If there is no drawbacks to writing to field as a string (don't THINK there is) the solution Dezsoe posted is the most efficient of all posted.

Dan
Dan911
 
Posts: 613
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Formating numbers

Postby dezsoe » Tue Jun 26, 2018 7:36 am

I think, that internally all fields are text fields. Setfield and Setfieldtext work on all fields. I made a quick test to format the input:

Code: Select all
    Public Sub Textfieldtexttyped_event(labelnumber As Integer, Ismainscreen As Boolean, text As String)
        If Ismainscreen Then
            If labelnumber = 21000 Then
                Dim str As String = UC.Getfielddouble(True, labelnumber).ToString("F4")
                UC.Setfieldtext(True, str, labelnumber)
            End If
        End If
    End Sub

Sorry, it's in VB. :) The only problem is that it formats the field only if you type the number. I mean, it won't format if you put the number there by Setfield, only if you use the keyboard. :(
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 18 guests