Function format_gold_k

Source
fn format_gold_k(gold: u64) -> String
Expand description

⚙️ Function: Formats the amount of gold earned in a match into a more readable “k” notation when appropriate.

This function takes an amount of gold as input and formats it into a human-readable string. If the amount is less than 1000, it returns the gold value as a simple string. If the gold is 1000 or more, it formats the value in “k” notation (e.g., 1500 becomes “1.5k”).

§Parameters:

  • gold: A u64 value representing the amount of gold earned by a player in a match.

§Returns:

  • String: A formatted string representing the gold amount. If the amount is less than 1000, it returns the value as is. For amounts equal to or greater than 1000, it returns a string in “k” notation (e.g., “1k”, “1.5k”) with a comma used as the decimal separator.

§Example:

let formatted_gold = format_gold_k(1500);
assert_eq!(formatted_gold, "1,5k");

§Notes:

  • For gold values with no fractional part, the result will omit the decimal point (e.g., 1000 will be formatted as “1k” instead of “1.0k”).
  • The function uses a comma to separate the decimal part, following European formatting conventions.