Change formatting of decimals in stats
This commit is contained in:
@@ -34,6 +34,10 @@ export const formatTemperature = (temperature) =>
|
|||||||
? temperature
|
? temperature
|
||||||
: Number.parseFloat(temperature.toString()).toFixed(2)
|
: Number.parseFloat(temperature.toString()).toFixed(2)
|
||||||
|
|
||||||
|
//maximum of precision digits after decimal point, but no x.0
|
||||||
|
export const formatDecimal = (num, precision) =>
|
||||||
|
+parseFloat(Number.parseFloat(num).toFixed(precision))
|
||||||
|
|
||||||
export const getPreviousTemperature = (date) => {
|
export const getPreviousTemperature = (date) => {
|
||||||
const previousTemperature = getPreviousTemperatureForDate(date)
|
const previousTemperature = getPreviousTemperatureForDate(date)
|
||||||
return formatTemperature(previousTemperature)
|
return formatTemperature(previousTemperature)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { StyleSheet, View } from 'react-native'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
import AppText from '../common/app-text'
|
import AppText from '../common/app-text'
|
||||||
|
import { formatDecimal } from '../helpers/cycle-day'
|
||||||
import { Sizes, Spacing, Typography } from '../../styles'
|
import { Sizes, Spacing, Typography } from '../../styles'
|
||||||
|
|
||||||
const StatsOverview = ({ data }) => {
|
const StatsOverview = ({ data }) => {
|
||||||
@@ -16,7 +16,9 @@ StatsOverview.propTypes = {
|
|||||||
|
|
||||||
const Row = ({ rowContent }) => {
|
const Row = ({ rowContent }) => {
|
||||||
const isStandardDeviation = rowContent[1].includes('deviation')
|
const isStandardDeviation = rowContent[1].includes('deviation')
|
||||||
|
if (isStandardDeviation && rowContent[0] !== '—') {
|
||||||
|
rowContent[0] = formatDecimal(rowContent[0], 1)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<View style={styles.row}>
|
<View style={styles.row}>
|
||||||
<Cell content={rowContent[0]} isLeft />
|
<Cell content={rowContent[0]} isLeft />
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import PeriodDetailsModal from './PeriodDetailsModal'
|
|||||||
|
|
||||||
import cycleModule from '../../lib/cycle'
|
import cycleModule from '../../lib/cycle'
|
||||||
import { getCycleLengthStats as getCycleInfo } from '../../lib/cycle-length'
|
import { getCycleLengthStats as getCycleInfo } from '../../lib/cycle-length'
|
||||||
|
import { formatDecimal } from '../helpers/cycle-day'
|
||||||
|
|
||||||
import { Containers, Sizes, Spacing, Typography } from '../../styles'
|
import { Containers, Sizes, Spacing, Typography } from '../../styles'
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const Stats = () => {
|
|||||||
numberOfCycles > 0
|
numberOfCycles > 0
|
||||||
? getCycleInfo(cycleLengths)
|
? getCycleInfo(cycleLengths)
|
||||||
: { minimum: '—', maximum: '—', stdDeviation: '—' }
|
: { minimum: '—', maximum: '—', stdDeviation: '—' }
|
||||||
|
|
||||||
const standardDeviation = cycleData.stdDeviation
|
const standardDeviation = cycleData.stdDeviation
|
||||||
? cycleData.stdDeviation
|
? cycleData.stdDeviation
|
||||||
: '—'
|
: '—'
|
||||||
@@ -37,6 +39,10 @@ const Stats = () => {
|
|||||||
[numberOfCycles, t('overview.completedCycles')],
|
[numberOfCycles, t('overview.completedCycles')],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (cycleData.mean) {
|
||||||
|
cycleData.mean = formatDecimal(cycleData.mean, 1)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={styles.pageContainer}>
|
<SafeAreaView style={styles.pageContainer}>
|
||||||
<ScrollView contentContainerStyle={styles.overviewContainer}>
|
<ScrollView contentContainerStyle={styles.overviewContainer}>
|
||||||
|
|||||||
Reference in New Issue
Block a user