From 528fe15819882bc4e4be7df5fa57f0d02115ec2d Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Mon, 7 Dec 2020 11:36:05 -0800 Subject: [PATCH] Add million support --- src/post.rs | 2 +- src/subreddit.rs | 2 +- src/utils.rs | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/post.rs b/src/post.rs index 7613f88..b726d45 100644 --- a/src/post.rs +++ b/src/post.rs @@ -1,5 +1,5 @@ // CRATES -use crate::utils::{format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post, format_num}; +use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post}; use actix_web::{get, http::StatusCode, web, HttpResponse, Result}; use askama::Template; use chrono::{TimeZone, Utc}; diff --git a/src/subreddit.rs b/src/subreddit.rs index 859e642..585f6ae 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -1,5 +1,5 @@ // CRATES -use crate::utils::{fetch_posts, format_url, request, val, ErrorTemplate, Params, Post, Subreddit, format_num}; +use crate::utils::{fetch_posts, format_num, format_url, request, val, ErrorTemplate, Params, Post, Subreddit}; use actix_web::{get, http::StatusCode, web, HttpResponse, Result}; use askama::Template; use std::convert::TryInto; diff --git a/src/utils.rs b/src/utils.rs index 1657878..c638d10 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -88,7 +88,13 @@ pub async fn format_url(url: &str) -> String { } pub fn format_num(num: i64) -> String { - return if num > 1000 { format!("{}k", num / 1000) } else { num.to_string() }; + if num > 1000000 { + format!("{}m", num / 1000000) + } else if num > 1000 { + format!("{}k", num / 1000) + } else { + num.to_string() + } } //