Add million support

This commit is contained in:
spikecodes 2020-12-07 11:36:05 -08:00
parent 8509f6e22d
commit 528fe15819
3 changed files with 9 additions and 3 deletions

View file

@ -1,5 +1,5 @@
// CRATES // 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 actix_web::{get, http::StatusCode, web, HttpResponse, Result};
use askama::Template; use askama::Template;
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};

View file

@ -1,5 +1,5 @@
// CRATES // 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 actix_web::{get, http::StatusCode, web, HttpResponse, Result};
use askama::Template; use askama::Template;
use std::convert::TryInto; use std::convert::TryInto;

View file

@ -88,7 +88,13 @@ pub async fn format_url(url: &str) -> String {
} }
pub fn format_num(num: i64) -> 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()
}
} }
// //