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?