<commit_before>import Foundation

// This module has the NSNumberFormatter methods we need
import Artsy_UILabels

extension Int {


    /// Turns a thousand dollars' worth of cents (like 1_000_00) into "$1k", etc.
    func metricSuffixify() -> String {
        guard self > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(self) }
        return NSNumberFormatter.currencyStringForDollarCents(removeKSignificantDigits()) + "k"
    }

    func roundCentsToNearestThousandAndFormat() -> String {
        guard self > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(self) }
        return NSNumberFormatter.currencyStringForDollarCents(roundCentsToNearestThousand())
    }

    func convertToDollarString() -> String {
        return NSNumberFormatter.currencyStringForDollarCents(self)
    }


    // Rounds a number (cents) down to the nearest thousand dollars.
    // So 1545_00 becomes 1000_00.
    // Numbers less than a thousand dollars are returned as-is.
    func roundCentsToNearestThousand() -> Int {
        guard self > 1000_00 else { return self }
        // currencyStringForDollarCents will round something like 1500_00 up to $2000, but we want to round _down_.
        // So we divide by 1000_00 to turn us into dollars momentarily, then back into cents to remove their significant digits.
        let dollarsK = Int(floor(Float(self) / Float(1000_00)))
        let cents = Int(dollarsK) * 1000_00
        return cents
    }

    // Removes three significant digits from number.
    private func removeKSignificantDigits() -> Int {
        return roundCentsToNearestThousand() / 1000
    }
}

// Within the context of live auctions, numbers that represent cents
// are all UInt64 to ensure consistency across devices, and that 
// people can make large bids.

extension UInt64 {

    private var number: NSNumber {
        return NSNumber(unsignedLongLong: self)
    }

    /// Turns a thousand dollars' worth of cents (like 1_000_00) into "$1k", etc.
    func metricSuffixify() -> String {
        guard self > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(self.number) }

        return NSNumberFormatter.currencyStringForDollarCents(removeKSignificantDigits().number) + "k"
    }

    func roundCentsToNearestThousandAndFormat() -> String {
        guard self > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(self.number) }
        return NSNumberFormatter.currencyStringForDollarCents(roundCentsToNearestThousand().number)
    }

    func convertToDollarString() -> String {
        return NSNumberFormatter.currencyStringForDollarCents(self.number)
    }

    // Rounds a number (cents) down to the nearest thousand dollars.
    // So 1545_00 becomes 1000_00.
    // Numbers less than a thousand dollars are returned as-is.
    func roundCentsToNearestThousand() -> UInt64 {
        guard self > 1000_00 else { return self }
        // currencyStringForDollarCents will round something like 1500_00 up to $2000, but we want to round _down_.
        // So we divide by 1000_00 to turn us into dollars momentarily, then back into cents to remove their significant digits.
        let dollarsK = UInt64(floor(Float(self) / Float(1000_00)))
        let cents = UInt64(dollarsK) * 1000_00
        return cents<commit_msg>Make Int + UInt64 share the same code for showing dollar strings<commit_after>import Foundation

// This module has the NSNumberFormatter methods we need
import Artsy_UILabels

protocol Centable {
    var number: NSNumber { get }
}

extension Int : Centable {
    var number: NSNumber {
        return self
    }
}

// Within the context of live auctions, numbers that represent cents
// are all UInt64 to ensure consistency across devices, and that
// people can make large bids.

extension UInt64 : Centable {
    var number: NSNumber {
        return NSNumber(unsignedLongLong: self)
    }
}

extension Centable {

    /// Turns a thousand dollars' worth of cents (like 1_000_00) into "$1k", etc.
    func metricSuffixify() -> String {
        let number = self.number
        guard number.intValue > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(number) }
        return NSNumberFormatter.currencyStringForDollarCents(removeKSignificantDigits().number) + "k"
    }

    func roundCentsToNearestThousandAndFormat() -> String {
        let number = self.number
        guard number.intValue > 1000_00 else { return NSNumberFormatter.currencyStringForDollarCents(number) }
        return NSNumberFormatter.currencyStringForDollarCents(roundCentsToNearestThousand().number)
    }

    func convertToDollarString() -> String {
        return NSNumberFormatter.currencyStringForDollarCents(self.number)
    }

    // Rounds a number (cents) down to the nearest thousand dollars.
    // So 1545_00 becomes 1000_00.
    // Numbers less than a thousand dollars are returned as-is.
    func roundCentsToNearestThousand() -> UInt64 {
        let number = self.number
        guard number.intValue > 1000_00 else { return number.unsignedLongLongValue }
        // currencyStringForDollarCents will round something like 1500_00 up to $2000, but we want to round _down_.
        // So we divide by 1000_00 to turn us into dollars momentarily, then back into cents to remove their significant digits.
        let dollarsK = UInt64(floor(Float(self.number) / Float(1000_00)))
        let cents = dollarsK * 1000_00
        return cents
{'fraction_non_alphanumeric': 0.07116721551408708, 'fraction_numerical': 0.04006586169045005, 'mean_word_length': 3.2844827586206895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2881510', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1481, 'n_words': 492}