How To Send Variable To Another Script And Back?

I want to send a double (Points) and a string (abbrevPoints) to the script below to abbreviate Points, convert it to a string and save it to abbrevPoints.

using System;

public class Abbreviator
{
    public string FormatNumber(double amount, string formattedString)
    {
        if (amount < 1e3)
        {
            formattedString = (Math.Round(amount * 1000) / 1000).ToString();
        }
        else if (amount >= 1e3 && amount < 1e6)
        {
            formattedString = ((Math.Round(amount * 1000) / 1000) / 1e3).ToString() + "K";
        }

        return formattedString;
    }
}

I’m trying to call this in the other script like so:

abbrevPoints = FormatNumber(Points, abbrevPoints)

I’m aware that this isn’t how to do this (clearly) and I can’t find anything on the Unity docs that have been helpful. How do I go about doing this?

Because that’s default C# stuff. :wink:

String formatting is well documented. Even something like formatting numbers to KB/MB/etc.

This is basic C# or even object-oriented programming stuff more than it is Unity stuff. In general, to be able to use a method of a class, you first need to create an instance of that class, and then call its method.

In this case though, this can just be a static method since it does not need any instance variables. You do this by writing:
public static string FormatNumber(…

And then you can just call it directly as: Abbreviator.FormatNumber(…