Skip to content

Compare changes

Choose two branches to see what one has that the other does not, then open a pull request for it.

Open a pull request

1 commit

2 files+19−180/2 viewed
+4−3
66
77 /**
88 * Dollars, to the cent; amounts under a dollar keep up to four places, so
9− * a run that cost a fraction of a cent does not read as nothing.
9+ * a run that cost a fraction of a cent does not read as nothing. With
10+ * `cents`, always to the cent: for statements, where figures sit in columns.
1011 */
11−export function usd(micros: number | null | undefined, { signed = false }: { signed?: boolean } = {}): string {
12+export function usd(micros: number | null | undefined, { signed = false, cents = false }: { signed?: boolean; cents?: boolean } = {}): string {
1213 if (micros == null) return "—";
1314 const dollars = micros / MICROS_PER_DOLLAR;
14− const text = (Math.abs(dollars) < 1 ? SMALL : WHOLE).format(Math.abs(dollars));
15+ const text = (Math.abs(dollars) < 1 && !cents ? SMALL : WHOLE).format(Math.abs(dollars));
1516 if (dollars < 0) return `−${text}`;
1617 return signed && dollars > 0 ? `+${text}` : text;
1718 }
+15−15
665665 title: "Usage sold",
666666 note:
667667 included > 0
668− ? `What workspaces paid for usage (${usd(o.usageMicros)}) and their plan's included usage (${usd(included)}), against what it cost`
668+ ? `What workspaces paid for usage (${usd(o.usageMicros, { cents: true })}) and their plan's included usage (${usd(included, { cents: true })}), against what it cost`
669669 : "What workspaces paid for usage, against what that usage cost",
670670 in: usageIn,
671671 cost: usageCost,
676676 title: "Running g1t",
677677 note:
678678 included > 0
679− ? `Plans (${usd(o.plansMicros)}) less the included usage they paid for, against Workers, D1, KV, Queues and the rest`
679+ ? `Plans (${usd(o.plansMicros, { cents: true })}) less the included usage they paid for, against Workers, D1, KV, Queues and the rest`
680680 : "Plans, against Workers, D1, KV, Queues and the rest of the platform",
681681 in: o.plansMicros - included,
682682 cost: running,
696696 : []),
697697 {
698698 title: "Given away",
699− note: givenParts.length > 0 ? givenParts.map(([why, micros]) => `${why} ${usd(micros)}`).join(" · ") : "Nothing this range",
699+ note: givenParts.length > 0 ? givenParts.map(([why, micros]) => `${why} ${usd(micros, { cents: true })}`).join(" · ") : "Nothing this range",
700700 in: null,
701701 cost: given,
702702 result: null,
710710 <Stat
711711 label="Margin on usage sold"
712712 value={percentLabel(usagePercent)}
713− hint={`${usd(usageIn)} paid for usage that cost ${usd(usageCost)}`}
713+ hint={`${usd(usageIn, { cents: true })} paid for usage that cost ${usd(usageCost, { cents: true })}`}
714714 tone={marginTone(usagePercent, floor)}
715715 />
716716 <Stat
717717 label="Given away on purpose"
718− value={usd(given)}
719− hint={givenParts.length > 0 ? givenParts.map(([why, micros]) => `${usd(micros)} ${why}`).join(", ") : "Nothing given this range"}
718+ value={usd(given, { cents: true })}
719+ hint={givenParts.length > 0 ? givenParts.map(([why, micros]) => `${usd(micros, { cents: true })} ${why}`).join(", ") : "Nothing given this range"}
720720 />
721721 <Stat
722722 label="Who g1t paid"
723− value={usd(o.costMicros)}
724− hint={`Cloudflare ${usd(o.cloudflareCostMicros ?? o.costMicros - (o.modelsCostMicros ?? 0))}, model providers ${usd(o.modelsCostMicros ?? 0)}`}
723+ value={usd(o.costMicros, { cents: true })}
724+ hint={`Cloudflare ${usd(o.cloudflareCostMicros ?? o.costMicros - (o.modelsCostMicros ?? 0), { cents: true })}, model providers ${usd(o.modelsCostMicros ?? 0, { cents: true })}`}
725725 />
726726 <Stat
727727 label="Proposals waiting"
749749 <span className="text-fg">{row.title}</span>
750750 <span className="block text-xs text-faint">{row.note}</span>
751751 </td>
752− <td className="tabular px-4 py-2.5 text-right">{row.in == null ? <span className="text-faint">—</span> : usd(row.in)}</td>
753− <td className="tabular px-4 py-2.5 text-right">{usd(row.cost)}</td>
752+ <td className="tabular px-4 py-2.5 text-right">{row.in == null ? <span className="text-faint">—</span> : usd(row.in, { cents: true })}</td>
753+ <td className="tabular px-4 py-2.5 text-right">{usd(row.cost, { cents: true })}</td>
754754 <td className={`tabular px-4 py-2.5 text-right sm:pr-5 ${resultClass(row.tone)}`}>
755− {row.result == null ? "a budget" : usd(row.result, { signed: true })}
755+ {row.result == null ? "a budget" : usd(row.result, { signed: true, cents: true })}
756756 </td>
757757 </tr>
758758 ))}
760760 <td className="px-4 py-2.5 sm:px-5">
761761 <span className="font-medium text-fg">All in</span>
762762 <span className="block text-xs text-faint">
763− {given > 0 ? `${usd(given)} of the cost was given away on purpose; without it, ${usd(net + given, { signed: true })}` : "Everything above"}
763+ {given > 0 ? `${usd(given, { cents: true })} of the cost was given away on purpose; without it, ${usd(net + given, { signed: true, cents: true })}` : "Everything above"}
764764 </span>
765765 </td>
766− <td className="tabular px-4 py-2.5 text-right font-medium">{usd(moneyIn)}</td>
767− <td className="tabular px-4 py-2.5 text-right font-medium">{usd(spent)}</td>
768− <td className="tabular px-4 py-2.5 text-right font-medium text-fg sm:pr-5">{usd(net, { signed: true })}</td>
766+ <td className="tabular px-4 py-2.5 text-right font-medium">{usd(moneyIn, { cents: true })}</td>
767+ <td className="tabular px-4 py-2.5 text-right font-medium">{usd(spent, { cents: true })}</td>
768+ <td className="tabular px-4 py-2.5 text-right font-medium text-fg sm:pr-5">{usd(net, { signed: true, cents: true })}</td>
769769 </tr>
770770 </tbody>
771771 </table>